Diferencia entre revisiones de «Curso Python DGA 2011/inmersion python/chuleta»
De WikiEducator
(Página creada con ' ==Comprensión de listas== <source lang="python"> >>> [str(x) for x in range(10)] </source>') |
|||
| Línea 1: | Línea 1: | ||
| − | + | == Aplicar función a lista == | |
| + | <source lang="python"> | ||
| + | >>> map(str, range(10)) | ||
| + | ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] | ||
| + | >>> ', '.join(map(str, range(10))) | ||
| + | '0, 1, 2, 3, 4, 5, 6, 7, 8, 9' | ||
| + | </source> | ||
==Comprensión de listas== | ==Comprensión de listas== | ||
<source lang="python"> | <source lang="python"> | ||
Revisión de 13:52 5 sep 2011
Aplicar función a lista
>>> map(str, range(10)) ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] >>> ', '.join(map(str, range(10))) '0, 1, 2, 3, 4, 5, 6, 7, 8, 9'
Comprensión de listas
>>> [str(x) for x in range(10)]