Skip to main content

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.

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.

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
class diccionario:

    def __init__(self):
       self.listadatos = []

    def muestredatos(self):
        return self.listadatos


# diccionario es aquel que agrupa n cantidad de valores
sopyvariable = "mario"

mydiccionario = {
    "nombre": sopyvariable,
    "apellido": "Jimenez",
    "estado": True
}

# casado
mydiccionario2 = {
    "nombre": "Isaac",
    "casado": True,
    "apellido": "Jimenez",
    "estado": True,
    "fecha": "2023"
}
Access any value by passing its key as a string index:
print(mydiccionario["nombre"])   # mario
print(mydiccionario2["fecha"])   # 2023
Dictionaries are unordered in concept (though Python 3.7+ preserves insertion order) and each key must be unique within the same dictionary.

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
arreglo = [
    "Mario",
    True,
    "2023",
    True,
    "Jimenez"
]

arreglo2 = [
    "Isaac",
    "Jimenez",
    True,
    "2023",
    True
]

arreglos = [arreglo, arreglo2]

soyarreglo = [mydiccionario, mydiccionario2]

# un arreglo es un matriz unidimensional, que permite almacenar datos
# arreglo[0 ,"mario"]

# list de diccionario es una matriz multidimensional

for item in soyarreglo:
    print("Key o elemento de la lista", item["apellido"])
The 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:
Key o elemento de la lista Jimenez
Key o elemento de la lista Jimenez

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.
FeatureList (arreglo)Dictionary (mydiccionario)
AccessBy integer index — arreglo[0]"Mario"By string key — mydiccionario["nombre"]"mario"
OrderAlways ordered; index 0 is always firstInsertion-ordered (Python 3.7+), but accessed by key
ReadabilityLow — you must remember what each index meansHigh — keys are self-documenting labels
FlexibilityAll elements treated the sameEach key-value pair is independent
Best forSequences of uniform valuesRecords 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.
1

Named import — import a single function

from plantillamenu import mostrarmenu
Only mostrarmenu is brought into the current namespace. mostrarmenu2 and mostrarmenu3 are not available.
2

Wildcard import — import everything

from funciones import *
Every public function defined in funciones.py becomes directly available. Here that gives us saludos() and menuprincipal().
3

Module import — import the whole file as an object

import nuevomenus
The module itself becomes an object. You access its contents with dot notation: nuevomenus.nuevomenus().
Putting it all together, prinicipal.py is the entry point — it wires together the three modules and calls each one:
semana4/prinicipal.py
# Se le conoce como librerias (Son class), modulos (Clases), funciones

from plantillamenu import mostrarmenu
from funciones import *
import nuevomenus

saludos()
print(mostrarmenu())
testdevariable = nuevomenus.nuevomenus()

# en el principal creo la interfaz grafica.

The modules being imported

def mostrarmenu():
    return "Soy un menu"

def mostrarmenu2():
    return "Soy un menu 2"

def mostrarmenu3():
    return "Soy un menu3"


class Menu:
    def __init__(self):
        self.dato = ""
When prinicipal.py runs, the output is:
Saludos
Soy un menu
estoy en nuevomenus
Prefer explicit imports (from module import name) over wildcard imports (from module import *) in production code. Explicit imports make it immediately clear where each name comes from, prevent accidental name collisions, and make code easier to read and refactor. Wildcards are convenient for quick experiments but can create hard-to-debug surprises in larger codebases.
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.

Build docs developers (and LLMs) love