-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy path3.9.py
More file actions
executable file
·39 lines (22 loc) · 886 Bytes
/
3.9.py
File metadata and controls
executable file
·39 lines (22 loc) · 886 Bytes
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
#!/usr/bin/env python3.9
from passed import passed
# https://docs.python.org/3.9/whatsnew/3.9.html
# https://docs.python.org/3.9/whatsnew/3.9.html#dictionary-merge-update-operators
dict_1 = {'a': 0, 'b': 2}
dict_2 = {'a': 1, 'c': 3}
# Merging dictionaries
assert dict_1 | dict_2 == {'a': 1, 'b': 2, 'c': 3}
dict_1 |= dict_2
# Updating a dictionary
assert dict_1 | dict_2 == {'a': 1, 'b': 2, 'c': 3}
assert dict_1 == {'a': 1, 'b': 2, 'c': 3}
# In type annotations you can now use built-in collection types such as list
# and dict as generic types instead of importing the corresponding
# capitalized types.
# https://docs.python.org/3.9/whatsnew/3.9.html#pep-585-builtin-generic-types
def is_list(a_list: list[int]) -> bool:
return isinstance(a_list, list)
assert is_list([1, 2, 3])
assert 'ab'.removeprefix('a') == 'b'
assert 'ab'.removesuffix('b') == 'a'
passed()