How to use cycle() to repeat the contents its arguments in Python

1 Answer

0 votes
from itertools import *     

for val in zip(range(5), cycle(['a', 'b'])):         
    print(val)


    
   
'''
run:
 
(0, 'a')
(1, 'b')
(2, 'a')
(3, 'b')
(4, 'a')

'''

 



answered May 21, 2019 by avibootz
...