-
-
Save IndhumathyChelliah/52bb217dd9f70a25b0d9419e1fcba618 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
#itertools.count() used in zip() | |
l1=[5,15,25] | |
l2=zip(itertools.count(),l1) | |
#It will return zip object which is an iterable instance of zip class | |
print (l2)#Output:<zip object at 0x032C92C8> | |
#we can convert zip object to list. | |
print (list(l2))#Output:[(0, 5), (1, 15), (2, 25)] | |
# We can access the zip object by using "for loop".This is more efficient way to access large sequences.It won't be memory intensive. | |
l3=zip(itertools.count(),l1) | |
for i in l3: | |
print (i) | |
''' | |
Output: | |
(0, 5) | |
(1, 15) | |
(2, 25) | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment