List comprehensions
This commit is contained in:
parent
8bd574b39c
commit
65264ff543
|
@ -282,6 +282,18 @@ orders.append('tulips')
|
|||
|
||||
You can add lists like this: `['list1', 'stuff'] + ['list2', 'stuff']` but need to use `lst1 + lst2` and not `[lst1] + [lst2]`
|
||||
|
||||
# List Comprehensions
|
||||
|
||||
Say you only want to allow people over the height of 161 to ride your roller coaster for safety reasons. You could do this to create a list of only those heights about 161.
|
||||
|
||||
```
|
||||
heights = [161, 164, 156, 144, 158, 170, 163, 163, 157]
|
||||
can_ride_coaster = []
|
||||
can_ride_coaster = [height for height in heights if height > 161]
|
||||
|
||||
print(can_ride_coaster)
|
||||
```
|
||||
|
||||
## Ranges
|
||||
|
||||
You can get a range of numbers using `range()`
|
||||
|
|
Loading…
Reference in New Issue