-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeCa_list_func.py
More file actions
58 lines (37 loc) · 881 Bytes
/
CodeCa_list_func.py
File metadata and controls
58 lines (37 loc) · 881 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
""" Iterations with :range()" and for loop
two methods:
1.
for item in list:
print item
2.
for i in range(len(list)):
print list[i]
In the 1st method it's impossible to modify the list, but in the 2nd it is.
"""
# With numbers
n = [3, 5, 7]
def total(numbers):
result = 0
for i in range(len(numbers)):
result += numbers[i]
return result
print total(n)
# With strings
n = ["Michael", "Lieberman"]
# Add your function here
def join_strings(words):
result = ""
for item in words:
result += item
return result
print join_strings(n)
# takes multiple lists and create a common list from them
n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]
# Add your function here
def flatten(lists):
results = []
for numbers in lists:
for number in numbers:
results.append(number)
return results
print flatten(n)