Skip to content

Commit 958de48

Browse files
author
Anastasiia Novikova
committed
Add about_dictionaries
1 parent 4d44cf3 commit 958de48

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

koans/about_dictionaries.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
from koans_plugs import *
2+
3+
4+
def test_create_dictionary_with_literal():
5+
"""
6+
Словарь в Python можно создать с помощью литерала словаря
7+
"""
8+
d = {
9+
'a': 1,
10+
'b': 2
11+
}
12+
assert d == _____
13+
14+
15+
def test_create_dictionary_with_constructor():
16+
"""
17+
Словарь в Python можно создать с помощью конструктора словаря
18+
"""
19+
d = dict(a=1,
20+
b=2
21+
)
22+
assert d == _____
23+
24+
25+
def test_create_dictionary_with_list_of_tuples():
26+
"""
27+
Словарь в Python можно создать из списка кортежей
28+
"""
29+
list_of_tuples = [('a', 1), ('b', 2), ('c', 3)]
30+
d = dict(list_of_tuples)
31+
32+
assert d == _____
33+
34+
35+
def test_get_value_by_key():
36+
"""
37+
В словаре можно получать значение по ключу
38+
"""
39+
d = {
40+
'a': 1,
41+
'b': 2
42+
}
43+
assert d['a'] == _____
44+
45+
46+
def test_add_key_and_value_to_dictionary():
47+
"""
48+
В словарь можно добавлять пару ключ-значение
49+
"""
50+
d = {
51+
'a': 1,
52+
'b': 2
53+
}
54+
d['c'] = 3
55+
56+
assert d == ___
57+
58+
59+
def test_if_key_in_dict():
60+
"""
61+
Можно проверять, есть ли опредеоенный ключ в словаре
62+
"""
63+
d = {
64+
'a': 1,
65+
'b': 2
66+
}
67+
var = 'a' in d
68+
69+
assert var == ___
70+
71+
72+
def test_get_method():
73+
"""
74+
Можно устанавливать значение по умолчанию для ключей, которых нет в словаре с помощью метода словаря get()
75+
"""
76+
d = {
77+
'a': 1,
78+
'b': 2
79+
}
80+
var = d.get('c', 0)
81+
82+
assert var == ___

0 commit comments

Comments
 (0)