-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEnumerate___.py
47 lines (32 loc) · 1.13 KB
/
Enumerate___.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# l1 = ["Bhindi", "Aloo", "chopsticks", "chowmein"]
#
# # i = 1
# # for item in l1:
# # if i%2 is not 0:
# # print(f"Jarvis please buy {item}")
# # i += 1
#
# for index, item in enumerate(l1):
# if index%2==0:
# print(f"Jarvis please buy {item}")
# -----------------------------------------------PROGRAMIZ--------------------------------------------------------
# Example 1: How enumerate() works in Python?
grocery = ['bread', 'milk', 'butter']
enumerateGrocery = enumerate(grocery)
print(type(enumerateGrocery))
# converting to list
print(list(enumerateGrocery))
# changing the default counter
enumerateGrocery = enumerate(grocery, 10)
print(list(enumerateGrocery))
# Example 2: Looping Over an Enumerate object
grocery = ['bread', 'milk', 'butter']
for item in enumerate(grocery):
print(item)
print('\n')
for count, item in enumerate(grocery):
print(count, item)
print('\n')
# changing default start value
for count, item in enumerate(grocery, 100):
print(count, item)