Skip to content

Instantly share code, notes, and snippets.

@hodunov
Created November 4, 2021 19:25
Show Gist options
  • Select an option

  • Save hodunov/fc56808a72c9d7e77ccd84dec220880d to your computer and use it in GitHub Desktop.

Select an option

Save hodunov/fc56808a72c9d7e77ccd84dec220880d to your computer and use it in GitHub Desktop.

Revisions

  1. hodunov created this gist Nov 4, 2021.
    42 changes: 42 additions & 0 deletions dictionaries.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    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)