forked from mate-academy/py_dictionaries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython_lesson_05.py
41 lines (29 loc) · 975 Bytes
/
python_lesson_05.py
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
def sum_values(my_dictionary):
return sum(my_dictionary.values())
print(sum_values({10: 1, 100: 2, 1000: 3}))
def sum_even_keys(my_dictionary):
values = 0
for even in my_dictionary.values():
if even % 2 == 0:
values += even
return values
print(sum_even_keys({1: 5, 2: 2, 3: 3}))
def add_ten(my_dictionary):
for key, value in my_dictionary.items():
my_dictionary[key] = value + 10
return my_dictionary
print(add_ten({1:10, 2:20, 3:30}))
def values_that_are_keys(my_dictionary):
keys = []
for value in my_dictionary.values():
for key in my_dictionary.keys():
if key == value:
keys.append(key)
return keys
print(values_that_are_keys({1:100, 2:1, 3:4, 4:10}))
def max_key(my_dictionary):
maximum = max(my_dictionary.values())
for key in my_dictionary:
if my_dictionary[key] == maximum:
return key
print(max_key({1: 100, 2: 10000, 3: 4, 4: 1000000}))