Enumerate function takes ordered iterable like string,list,tuple and gives items and its index
list(enumerate("oranges"))
>>> [(0, 'o'), (1, 'r'), (2, 'a'), (3, 'n'), (4, 'g'), (5, 'e'), (6, 's')]
#!/usr/bin/python3
def main():
for i,j in list(enumerate("oranges")):
print(i,j)
if __name__ == "__main__":
main()
#output
0 o
1 r
2 a
3 n
4 g
5 e
6 s
list(enumerate("oranges"))
>>> [(0, 'o'), (1, 'r'), (2, 'a'), (3, 'n'), (4, 'g'), (5, 'e'), (6, 's')]
#!/usr/bin/python3
def main():
for i,j in list(enumerate("oranges")):
print(i,j)
if __name__ == "__main__":
main()
#output
0 o
1 r
2 a
3 n
4 g
5 e
6 s
No comments:
Post a Comment