¡GoConqr estrena diseño! Cuéntanos qué te parece.

Mapa mental

Dictionaries

Suja Nair Inglés

Contenido del mapa

Dictionaries

  1. Definition

    • A data structure
      • Stores key-value pairs
      • Mutable and unordered
  2. Characteristics

    • Keys
      • Unique within a dictionary
      • Immutable types (e.g., strings, numbers, tuples)
    • Values
      • Can be of any data type
      • Can be duplicated
  3. Creating a Dictionary

    • Using curly braces
      • Syntax: {key1: value1, key2: value2}
    • Using the dict() constructor
      • Syntax: dict(key1=value1, key2=value2)
  4. Accessing Elements

    • Using keys
      • Syntax: dict_name[key]
    • Using get() method
      • Syntax: dict_name.get(key)
  5. Modifying a Dictionary

    • Adding new key-value pairs
      • Syntax: dict_name[new_key] = new_value
    • Updating existing key-value pairs
      • Syntax: dict_name[existing_key] = new_value
  6. Built-in functions

    • len()
      • Function that returns the number of items
      • Counts key-value pairs
      • Example: len(my_dict)
    • dict()
      • Create dictionary objects
    • keys()
      • Retrieves keys from a dictionary
      • Syntax: my_dict.keys()
    • values()
      • Retrieves values from the dictionary
      • Syntax: my_dict.values()
    • items()
      • Retrieves key-value pairs
      • Syntax: dict.items()
    • update()
      • Method to update dictionaries
        • Adds new key-value pairs
        • Updates existing key values
        • Syntax: dict1.update(dict2)
    • get()
      • Method for retrieving values
      • Syntax: dict.get(key, default)
    • del
      • Removes a specified item;
        • Syntax: del dictionary[key];
    • clear
      • Removes all items
      • Empties the dictionary
      • Example: my_dict.clear()
    • fromkeys()
      • A method for creating a new dictionary.
        • Examples
          • Creating a dictionary with specified keys.
            • Example: `dict.fromkeys(['a', 'b', 'c'])`
          • Creating a dictionary with specified keys and a default value.
            • Example: `dict.fromkeys(['x', 'y', 'z'], 0)`
    • copy()
      • Creates a shallow copy of a dictionary
        • dict.copy() method
    • pop()
      • Remove an item
        • Based on the provided key
          • Syntax: dict.pop(key[, default])
    • popitem()
      • Method to remove and return an arbitrary (last) key-value pair
    • setdefault()
      • Retrieve value if key exists
        • If key not present, add key with default value
          • Syntax: dict.setdefault(key, default=None)
    • max(), min()
      • max()
        • Returns the largest item;
      • min()
        • Returns the smallest item;
    • sorted()
      • Returns a sorted list of the dictionary keys
        • Example: sorted(d)

Información

Descripción
Mapa Mental sobre Dictionaries, creado por Suja Nair el 17/05/2025.
Creado por
Suja Nair
Visitas
1
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?