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
57 lines (42 loc) · 1.38 KB
/
advanced_test.py
File metadata and controls
57 lines (42 loc) · 1.38 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
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.
"""
return [i ** 2 for i in range(1, 21) if i % 2 == 0] [0:5]
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 {name: grade for name, grade in 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).
"""
return nested['c']['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'] = list(nested['b']) + [6]
return nested