Cartesian product of two lists in python
list1 = ['a', 'b'] list2 = [1, 2, 3, 4, 5]
Expected Output:
list3 = ['a1', 'a2', 'a3', 'a4', 'a5', 'b1', 'b2', 'b3', 'b4', 'b5']
Do a list comprehension, iterate over both the lists and add the strings, like
list3 = [i+str(j) for i in list1 for j in list2]
2.1m questions
2.1m answers
60 comments
57.0k users