Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python: find most common element in corresponding two lists
import itertools
a = [7, 3]
b = [3, 1, 2]
c = [4, 3, 5]
def allEqual(t):
same = True
if len(t) == 1:
return True
if len(t) == 0:
return False
for i in range(1, len(t)):
if t[i] != t[i - 1]:
same = False
i = len(t) - 1
else:
same = same and True
return same
combo = list(itertools.product(a, b, c))
# print list(itertools.permutations(a,2))
# print combo
# combo = [x for x in combo if x[0]==x[1]==x[2]]
# print combo
combo = [x for x in combo if allEqual(x)]
print combo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment