As your programs grow, two needs emerge together: a way to represent structured data (more expressive than a plain list), and a way to organise code across multiple files so the project stays maintainable. Python addresses both with dictionaries and its module system. Dictionaries let you store named fields in a single object — much like a database row — while modules let you write a function or class once and reuse it anywhere by importing it.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/marioaje/Python/llms.txt
Use this file to discover all available pages before exploring further.
Dictionary Basics
A dictionary (dict) maps keys to values. Keys are almost always strings; values can be any Python type. You create one with curly braces and access individual fields by their key name inside square brackets.
semana4/diccionario.py
List of Dictionaries
A list of dictionaries is one of the most common Python patterns for working with tabular-style data — the same idea behind a JSON array or a database result set. Each element in the list is a complete dictionary representing one record.semana4/diccionario.py
for loop iterates over soyarreglo. Each item is a full dictionary, so you retrieve the "apellido" field the same way you would on a standalone dict. The output will be:
Arrays / Lists vs. Dictionaries
Both structures store collections of values, but they serve different purposes. The code above includes both a plain list (arreglo) and a dictionary (mydiccionario) holding data about the same person, which makes the contrast easy to see.
| Feature | List (arreglo) | Dictionary (mydiccionario) |
|---|---|---|
| Access | By integer index — arreglo[0] → "Mario" | By string key — mydiccionario["nombre"] → "mario" |
| Order | Always ordered; index 0 is always first | Insertion-ordered (Python 3.7+), but accessed by key |
| Readability | Low — you must remember what each index means | High — keys are self-documenting labels |
| Flexibility | All elements treated the same | Each key-value pair is independent |
| Best for | Sequences of uniform values | Records with named fields (like a row of data) |
Use a list when the position of each element carries meaning or when you have a homogeneous sequence (e.g., a list of numbers to sum). Use a dictionary when each value has a name and you want to look it up by that name rather than by position.
Module Imports
Once a project grows beyond one file, splitting code into modules keeps each file focused. A module is simply a.py file. Python offers three ways to pull another module’s contents into the current file, all demonstrated in prinicipal.py.
Named import — import a single function
mostrarmenu is brought into the current namespace. mostrarmenu2 and mostrarmenu3 are not available.Wildcard import — import everything
funciones.py becomes directly available. Here that gives us saludos() and menuprincipal().prinicipal.py is the entry point — it wires together the three modules and calls each one:
semana4/prinicipal.py
The modules being imported
prinicipal.py runs, the output is:
The first time Python imports a module it compiles it to bytecode and saves the result in a
__pycache__/ directory next to the source file (e.g. __pycache__/plantillamenu.cpython-311.pyc). This folder is generated automatically — you do not need to create it yourself. On subsequent runs Python reuses the cached bytecode if the source file has not changed, making startup faster. It is safe to add __pycache__/ to your .gitignore so it is not committed to version control.