0
List1 = []

called List1 import random

for n in range(1000):
    y =  random.randrange(0,100000)
    List1.append(y)

    List2 = []

for n1 in range(1000):
    y1 =  random.randrange(0,100000)
    List2.append(y1)

first list, i want to see those numbers in #

eun ason
  • 29
  • 1
  • 5

1 Answers1

1

You can use sets and counters:

Numbers in List2 not in List1:

set_of_different_numbers = set(List2) - set(List1)

Occurences of numbers in List2:

from collections import Counter
occurence_count = Counter(List2)

Occurences of numbers in List2 that are not in List1:

occurence_in_disjunction = Counter([l for l in List2 if l in set_of_different_numbers])
ted
  • 13,596
  • 9
  • 65
  • 107
  • what would I then print to get the numbers in both lists on screen ted ? – eun ason Apr 08 '17 at 16:14
  • what do you mean by " get the numbers in both lists" ? you can just print `occurence_in_disjunction` to see the number of occurences of numbers in `List2` that are not in `List1`. – ted Apr 09 '17 at 12:53