hoop hoop - 1 month ago 5x
Python Question

cycle "for" in Python

I have to create a three new lists of items using two different lists.

list_one = ['one', 'two','three', 'four','five']
list_two = ['blue', 'green', 'white']

len(list_one) != len(list_two)

Now I should create an algorithm(a cycle) which can do this:
[oneblue, twoblue, threeblue, fourblue, fiveblue]
. Same for 'green' and 'white'.

I undestand that I should create three cycles but I don't know how.
I've tried to make a function like this but it doesn't works.

def mix():
i = 0
for i in range(len(list_one)):
new_list = list_one[i]+list_two[0]
i = i+1
return new_list

What am I doing wrong?

wim wim

I think you might be looking for itertools.product:

>>> [b + a for a,b in itertools.product(list_two, list_one)]