You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
python-gjk/8/list_comprehensions.md

22 lines
476 B
Markdown

# List Comprehensions
list comprehensions jsou super.
Dovolujou zkratit kod uplne strasne moc.
Je to prakticky `for` kterej dovoluje filtrovat.
Tohle:
```python
# chceme sebrat vsechna sudo cisla do 1000
n = []
for i in range(1000):
if i % 2 == 0:
n.append(i)
print(n)
```
Je ekvivalence:
```python
n = [i for i in range(1000) if i % 2 == 0]
print(n)
```
coz muzeme cist jako: "n je seznam vsech cisel do 1000 kde zbytek z deleni dvemi je nula, tl;dr vsech sudych cisel"