Outils pour utilisateurs

Outils du site


python:programmes:listes_operations

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
python:programmes:listes_operations [2013/03/23 19:45] rootpython:programmes:listes_operations [2013/03/23 20:10] (Version actuelle) root
Ligne 18: Ligne 18:
 <code python> <code python>
 >>> [x**2 for x in range(10) if x % 2 == 0] >>> [x**2 for x in range(10) if x % 2 == 0]
 +[0, 4, 16, 36, 64]
 +</code>
 +
 +Ou avec un générateur :
 +<code python>
 +>>> x = (x**2 for x in range(10) if x % 2 == 0)
 +>>> x
 +<generator object <genexpr> at 0x7f99a1f43640>
 +>>> list(x)
 [0, 4, 16, 36, 64] [0, 4, 16, 36, 64]
 </code> </code>
python/programmes/listes_operations.1364067907.txt.gz · Dernière modification : 2013/03/23 19:45 de root