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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -