Skip to content

Understanding Dictionaries (dict) and identifying use cases #4

@space-otter

Description

@space-otter

Build up a good understanding for dictionaries as a data structure and find use cases where it shines.

Dictionary (dict)

Definition: Unordered (ordered since Python 3.7), mutable, key-value pairs.

Syntax: my_dict = {'a': 1, 'b': 2}

Common operations & properties:

  • Access: my_dict['a']
  • Add/Update: my_dict['c'] = 3
  • Delete: del my_dict['b']
  • Keys/Values: my_dict.keys(), my_dict.values()
  • Items: my_dict.items()
  • Get with default: my_dict.get('d', 0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions