I have two lists like:
list1 = [\'square\',\'circle\',\'triangle\']
list2 = [\'red\',\'green\']
How can I create all permutations of these
How about
[x + y for x in list1 for y in list2] + [y + x for x in list1 for y in list2]
Example IPython interaction:
In [3]: list1 = ['square', 'circle', 'triangle']
In [4]: list2 = ['red', 'green']
In [5]: [x + y for x in list1 for y in list2] + [y + x for x in list1 for y in list2]
Out[5]:
['squarered',
'squaregreen',
'circlered',
'circlegreen',
'trianglered',
'trianglegreen',
'redsquare',
'greensquare',
'redcircle',
'greencircle',
'redtriangle',
'greentriangle']