Skip to content

Commit db4b9f8

Browse files
author
Sebastian Muthwill
committed
adds list comprehension
1 parent 316a851 commit db4b9f8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
Playground to test python concepts and standard functionalities
33

44
## Python functionalities
5-
[enumerate](enumerate.py)
5+
[enumeration](enumeration.py)
6+
[list_comprehension](list_comprehension.py)
7+

list_comprehension.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fruits = ["apple", "orange", "banana", "peach"]
2+
3+
# get first char of fruit with simple list comprehension
4+
fruit_chars = [fruit[0] for fruit in fruits]
5+
print(fruit_chars)
6+
7+
# get first char of fruit for specific fruit with list comprehension
8+
fruit_chars2 = [fruit[0] for fruit in fruits if fruit in ('apple', 'banana')]
9+
print(fruit_chars2)

0 commit comments

Comments
 (0)