-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9.2.1.py
More file actions
35 lines (24 loc) · 837 Bytes
/
Copy path9.2.1.py
File metadata and controls
35 lines (24 loc) · 837 Bytes
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
"""
Створіть власну реалізацію вбудованої функції enumerate під назвою with_index,
яка приймає два параметри: iterable і start, за замовчуванням 0.
Підказка: перегляньте документацію для функції enumerate.
"""
def with_index1(iterable, start=0):
res = []
i=0
while i < len(iterable):
key = i+start
value = iterable[i]
res1=(key, value)
res.append(res1)
i +=1
return res
#pass variant---------------
def with_index(iterable, start=0):
count = start
for elem in iterable:
yield (count, elem)
count += 1
iterable = [16, 46, 26, 36]
print(with_index1(iterable, start=20))
print(with_index(iterable, start=20))