-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy2221.py
More file actions
36 lines (31 loc) · 958 Bytes
/
py2221.py
File metadata and controls
36 lines (31 loc) · 958 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
# coded by h4sski
'''
https://adriann.github.io/programming_problems.html
Write a function that concatenates two lists.
[a,b,c], [1,2,3] → [a,b,c,1,2,3]
--------------------------------------------------------
Write a function that combines two lists by alternatingly
taking elements, e.g. [a,b,c], [1,2,3] → [a,1,b,2,c,3].
'''
list_a = ['a', 'b', 'c']
list_1 = [1, 2, 3]
def concatenate_lists(first, second):
for n in second:
first.append(n)
return first
def combine_lists(first, second):
list_output = []
if len(first) > len(second):
l = len(first)
else:
l = len(second)
for i in range(l):
list_output.append(first[i])
list_output.append(second[i])
return list_output
def main():
print(concatenate_lists(list_a.copy(), list_1))
# I coppied list_a to have it NOT-modified for second function
print(combine_lists(list_a, list_1))
if __name__ == '__main__':
main()