Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created Jul 5, 2020
Embed
What would you like to do?
import itertools
#itertools.repeat() used in zip()
l1=[5,15,25]
l2=zip(itertools.repeat(2),l1)
#It will return zip object which is an iterable instance of zip class
print (l2)#Output:<zip object at 0x032794E8>
#we can convert zip object to list.
print (list(l2))#Output:[(2, 5), (2, 15), (2, 25)]
# We can access zip object by using for loop.This is more efficient way to access large sequences.It won't be memory intensive.
l3=zip(itertools.repeat("hello"),l1)
for i in l3:
print (i)
'''
Output:
('hello', 5)
('hello', 15)
('hello', 25)
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment