forked from MojahiMotaung/python_dataTypes_test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvanced_test.py
More file actions
60 lines (47 loc) · 1.41 KB
/
advanced_test.py
File metadata and controls
60 lines (47 loc) · 1.41 KB
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
58
59
60
def create_squares_of_evens():
"""
Task:
- Create a list of squares for all even numbers from 1 to 20 using list comprehension.
Return:
- The list of squares of even numbers.
"""
the=[]
for i in range(2,11,2):
the.append(i**2)
return the
def convert_to_dict(students):
"""
Task:
- Convert the list of student tuples into a dictionary where the name is the key and the grade is the value.
Return:
- The dictionary created from the list of students.
"""
return dict(students)
def access_value_x(nested):
"""
Task:
- Access the value of 'x' from the nested dictionary `nested = {'a': [1, 2, 3], 'b': (4, 5), 'c': {'x': 10, 'y': 20}}`.
Return:
- The value of 'x' (which is 10).
"""
for x,y in nested.items():
if 'x' in y:
return (y['x'])
def append_to_list_in_dict(nested):
"""
Task:
- Append the value 6 to the list under key 'a' in the nested dictionary `nested = {'a': [1, 2, 3], 'b': (4, 5), 'c': {'x': 10, 'y': 20}}`.
Return:
- The updated dictionary.
"""
nested['a'].append(6)
return nested
def convert_tuple_to_list_and_append(nested):
"""
Task:
- Convert the tuple under key 'b' in the nested dictionary into a list and add the value 6 at the end.
Return:
- The updated dictionary.
"""
nested['b']=[4, 5, 6]
return nested