|
|
@ -1,4 +1,4 @@ |
|
|
|
#! /usr/bin/env python2 |
|
|
|
#! /usr/bin/env python3 |
|
|
|
|
|
|
|
# find the intersection of two lists including duplicate values |
|
|
|
|
|
|
@ -15,9 +15,9 @@ def intersection(xs, ys): |
|
|
|
freqs2 = frequencies(ys) |
|
|
|
|
|
|
|
intersection = [] |
|
|
|
for k, v in freqs1.iteritems(): |
|
|
|
for k, v in freqs1.items(): |
|
|
|
n = min(v, freqs2[k]) |
|
|
|
intersection.extend([k for _ in xrange(n)]) |
|
|
|
intersection.extend([k for _ in range(n)]) |
|
|
|
return intersection |
|
|
|
|
|
|
|
print intersection([1,4,2,6,10,4,4], [7,4,9,10,20,4,10]) |
|
|
|
print(intersection([1,4,2,6,10,4,4], [7,4,9,10,20,4,10])) |
|
|
|