Python: find most common element in corresponding two lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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