furas

product of lists

Apr 20th, 2019
95
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. values = ["A", "A", "B", "C", "A", "C", "C"]
  2. keys   = [ 1,   2,   3,   3,   4,  4,  5,  5 ]
  3.  
  4. data = dict()
  5. for char, number in zip(values, keys):
  6.     if number not in data:
  7.         data[number] = []
  8.     data[number].append(char)
  9. data = data.values()
  10. print(data)
  11.  
  12. import itertools
  13. result = [''.join(x) for x in itertools.product(*data)]
  14. print(result)
  15.  
  16. #result = ["AABAC", "AABCC", "AACAC", "AACCC"]
RAW Paste Data