python:programmes:multiple_loop_in_one
Différences
Ci-dessous, les différences entre deux révisions de la page.
| python:programmes:multiple_loop_in_one [2014/02/22 17:12] – créée root | python:programmes:multiple_loop_in_one [2014/02/22 17:17] (Version actuelle) – root | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== Boucles optimisées avec condition ====== | ====== Boucles optimisées avec condition ====== | ||
| - | + | <code python> | |
| - | [code python] | + | |
| [z for b in a for c in b for d in c ... for z in y] | [z for b in a for c in b for d in c ... for z in y] | ||
| Which would be like having this regular for-loop: | Which would be like having this regular for-loop: | ||
| Ligne 12: | Ligne 11: | ||
| for z in y: | for z in y: | ||
| # have z | # have z | ||
| - | [/code] | + | </code> |
| - | [code python] | + | <code python> |
| list(set(sorted([v for i in [dict(parser.items(x)) for x in parser.sections()] for k,v in i.items() if k.startswith(' | list(set(sorted([v for i in [dict(parser.items(x)) for x in parser.sections()] for k,v in i.items() if k.startswith(' | ||
| - | [/code] | + | </code> |
| - | [code python] | + | <code python> |
| vec = [[1,2,3], [4,5,6], [7,8,9]] | vec = [[1,2,3], [4,5,6], [7,8,9]] | ||
| print [num for elem in vec for num in elem] <----- this | print [num for elem in vec for num in elem] <----- this | ||
| >>> | >>> | ||
| - | [/code] | + | </code> |
python/programmes/multiple_loop_in_one.1393089149.txt.gz · Dernière modification : de root
