Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created Jul 5, 2020
Embed
What would you like to do?
import itertools
#times argument is not mentioned. It will result in infinite loop.
l1=itertools.repeat(2)
print (next(l1))#Output:2
print (next(l1))#Output:2
#string is used as an argument.times argument is mentioned as 10.It will repeat the string 10 times.
l2=itertools.repeat("hello",times=10)
for i in l2:
print (i,end=" ")#Output:hello hello hello hello hello hello hello hello hello hello
print (" ")
#list is used as argument
l3=itertools.repeat([1,2,3],times=3)
for i in l3:
print (i,end=" ")#Output:[1, 2, 3] [1, 2, 3] [1, 2, 3]
print (" ")
#tuple is used as an argument
l4=itertools.repeat(('red','blue'),times=3)
for i in l4:
print (i,end=" ")#Output:('red', 'blue') ('red', 'blue') ('red', 'blue')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment