- 2
Good morning sir. I want to do multiple loop in one for loop. Thanks you sir.
multiple lists in one for loop. https://code.sololearn.com/cIdeaaPuC6LI/?ref=app
1 Answer
+ 7
Malick Diagne ,
[edited]
i suppose that you wanted to combine / merge the 2 lists. this can be done with the zip() built-in function. it "groups" and returns the elements index wise.
*(if you don't like to use this function, you can use loops. in this case please give a feedback)
since the lists have not the same number of elements, not all elements of the longest list can be used. this is the reason why i have used zip().
names = ["malick","doussou","nana","sadibou"]
codimeds = ["reconditionning","count","production"]
for name, codimed in zip(names, codimeds):
print (f"{name} and {codimed}")
output is:
malick and reconditionning
doussou and count
nana and production