Created
November 4, 2021 19:25
-
-
Save hodunov/fc56808a72c9d7e77ccd84dec220880d to your computer and use it in GitHub Desktop.
Py dicts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_dict = {1: 'way', 2: 'apple'} | |
my_dict_2 = {1: 'way', 'value': 'apple'} | |
my_tuple = (1, 2, 3) | |
new_dict = dict([(1, 'way'), (2, 'apple')]) | |
student = { | |
'name': 'Bob', | |
'age': 20, | |
'id': [1, 2, 3, 4], | |
} | |
name = student.get('name') | |
if name: | |
print(f"name is {name}") | |
student['name'] = 'Ihor' | |
print(student) | |
ihor_name = student.pop('name') | |
last_item = student.popitem() | |
print(ihor_name) | |
print(last_item) | |
print(student) | |
del student | |
student.clear() | |
numbers = {x: x**2 for x in range(10)} | |
print(numbers) | |
numbers = {} | |
for x in range(10): | |
numbers[x] = x**2 | |
print(numbers) | |
print(2 in numbers) | |
for item in numbers.values(): | |
print(item) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment