Let's say I have
list1=['a','b']
and
list2=['d','c','e','f']
How can I join them into a third list without any two elements of list1
sharing an element of list2
?
Like this:
list3=['ad','bc','ae','bf']
You can use some nifty itertools tricks to achieve your result. Primarily, you want to zip both the lists, but as the former is shorter , you want to continue until you exhaust it
>>> from itertools import izip, cycle
>>> list1=['a','b']
>>> list2=['d','c','e','f']
>>> map(''.join, list(izip(cycle(list1), list2)))
['ad', 'bc', 'ae', 'bf']
I am using python 3.4.2 , and I am on windows 7