Skip to content

Commit 7b2ca6f

Browse files
authored
Create unit6_ex6.2.4.py
1 parent 5f246b6 commit 7b2ca6f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Diff for: unit6_ex6.2.4.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# exercise 6.2.4 from unit 6
2+
3+
'''
4+
Write a function called extend_list_x defined as follows:
5+
def extend_list_x(list_x, list_y):
6+
The function receives two lists list_y, list_x. The function expands list_x (changes it) so that it also contains list_y at the beginning, and returns list_x.
7+
8+
An example of running the extend_list_x function
9+
>>> x = [4, 5, 6]
10+
>>> y = [1, 2, 3]
11+
>>> extend_list_x(x, y)
12+
[1, 2, 3, 4, 5, 6]
13+
Guidelines
14+
Do not use the '+' operator.
15+
Do not use the extend method.
16+
17+
Attention, this is a challenge exercise... ready? Take your time, try to think outside
18+
the box and look for the trick to solve it.
19+
'''
20+
21+
def extend_list_x(list_x, list_y):
22+
list_x[:0] = list_y
23+
return list_x
24+
25+
def main():
26+
x = [4, 5, 6]
27+
y = [1, 2, 3]
28+
extended_list = extend_list_x(x, y)
29+
print(extended_list)
30+
31+
if __name__ == "__main__":
32+
main()

0 commit comments

Comments
 (0)