How to work with two lists as round robin python -


i have 2 lists like

num = [1,2,3,4] names = ['shiva','naga','sharath','krishna','pavan','adi','mulagala'] 

i want print 2 lists parallel , if 1 list(num) ends want repeat first list(num) till second(names) list ends.

now want output as

1 shiva 2 naga 3 sarath 4 krishna 1 pavan 2 adi 3 mulagala 

using itertools.cycle , zip:

>>> num = [1,2,3,4] >>> names = ['shiva','naga','sharath','krishna','pavan','adi','mulagala'] >>> import itertools >>> i, name in zip(itertools.cycle(num), names): ...     print('{} {}'.format(i, name)) ... 1 shiva 2 naga 3 sharath 4 krishna 1 pavan 2 adi 3 mulagala 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -