Skip to content

Instantly share code, notes, and snippets.

@hodunov
Created November 4, 2021 19:25
Show Gist options
  • Save hodunov/fc56808a72c9d7e77ccd84dec220880d to your computer and use it in GitHub Desktop.
Save hodunov/fc56808a72c9d7e77ccd84dec220880d to your computer and use it in GitHub Desktop.
Py dicts
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