-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab-dictionary.py
72 lines (51 loc) · 1.58 KB
/
lab-dictionary.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
countryLeaders = {"PL": "Duda", "US": "Trump"} # klucz:wartość
print(countryLeaders)
print(countryLeaders["US"])
countryLeaders["DE"] = "Merkel"
print(countryLeaders)
print(countryLeaders.keys())
print(countryLeaders.values())
print(countryLeaders.items())
# print(countryLeaders.popitem())
# print(countryLeaders)
#
# print(countryLeaders.popitem())
# print(countryLeaders)
#
# print(countryLeaders.popitem())
# print(countryLeaders)
print(countryLeaders.setdefault("FR", "Macron"))
print(countryLeaders)
print(countryLeaders.get("RU"))
newLeaders = {"RU": "Putin", "DE": "Scholz"}
print(newLeaders)
countryLeaders.update(newLeaders)
print(countryLeaders)
'''
exercises
'''
# Nadal analizujesz wydajność kanałów, jakimi można dotrzeć do klientów. Każdorazowo po zmianie słownika wyświetl
# jego zawartość
#
# 1. Utwórz obiekt dictionary o nazwie chanels z następującymi kluczami i wartościami:
# -Google - 1480
# -Email - 300
# -Natural Traffic - 440
# -TV Spot - 700
chanels = {"Google": 1480, "Email": 300, "Natural Traffic": 440, "TV Spot": 700}
print(chanels)
# 2. Wyświetl wartość skojarzoną z kluczem "Email"
print(chanels["Email"])
# 3. Utwórz nowy słownik chanelsUpdate z kluczami i wartościami:
# -Natural Traffic - 520
# -News - 600
chanelsUpdate = {"Natural Traffic": 520, "News": 600}
print(chanelsUpdate)
# 4.Zaktualizuj słownik chanels wartościami z chanelsUpdate
chanels.update(chanelsUpdate)
print(chanels)
# 5. Wyświetl wszystkie klucze z chanels
print(chanels.keys())
# 6. Usuń wartość 'Email' ze słownika
chanels.pop("Email")
print(chanels)