Dux-Courses Evaluaciones
DOCUMENTATIONCOURSESROADMAPRANKINGBLOGPLAYGROUND
LoginSign Up
Aurum-Courses

Aurum Courses is an advanced learning and evaluation platform designed to accelerate your tech career. We provide an immersive environment filled with challenges, technical documentation, and verifyable certificates for frontend, backend, and fullstack technologies.

Platform Links

  • Interactive Courses
  • Technical Documentation
  • Tech Blog & Articles
  • Mi Perfil y Progreso

About the Project

  • About the Project
  • Contact & Support

Legal & Compliance

  • Privacy Policy
  • Terms of Service
  • Cookies Management
© 2026 Aurum-Courses. All rights reserved. Made with passion for the developer ecosystem.

Desarrollado por Aurumdux

Docs/Python/Generadores e Iteradores
Avanzadopython

Generadores e Iteradores

Crea secuencias perezosas (lazy) con generadores para procesar grandes volumenes de datos.

Que es un generador

Un generador es una funcion que usa yield en lugar de return. Produce valores uno a uno bajo demanda, sin almacenar toda la secuencia en memoria.
python
1def fibonacci(n):
2    a, b = 0, 1
3    for _ in range(n):
4        yield a
5        a, b = b, a + b
6
7for num in fibonacci(10):
8    print(num, end=" ")
9# 0 1 1 2 3 5 8 13 21 34

Generator Expressions

Similar a list comprehensions, pero usan parentesis () y son lazy: no calculan los valores hasta que se necesitan.
python
1# List comprehension (almacena todo en memoria)
2lista = [x**2 for x in range(1_000_000)]
3
4# Generator expression (lazy, eficiente)
5gen = (x**2 for x in range(1_000_000))
6print(next(gen))  # 0
7print(next(gen))  # 1
8print(sum(gen))   # Suma el resto sin cargar en memoria
← AnteriorLectura y Escritura de ArchivosSiguiente →Modulos y Paquetes