-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_comprehesion.py
More file actions
23 lines (17 loc) · 857 Bytes
/
list_comprehesion.py
File metadata and controls
23 lines (17 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# list compression = a way to create a new list with less syntax
# can mimic certain lambda functions, easier to read
# list = [expression for item in iterable]
# list = [expression for item in iterable if conditional]
# list = [expression if/else for item in iterable]
# squares = [] # create an empty list
# for i in range(1, 11): # create a for loop
# squares.append(i * i) # define what each loop iteration should do
# print(squares)
#
# square = [i * i for i in range(1,11)]
# print(square)
students = [100,90, 80, 70, 60, 50, 40, 30, 0]
# passed_students = list(filter(lambda x: x >= 60, students))
# passed_students = [i for i in students if i >= 60]
passed_students = [i if i >= 60 else "FAILED" for i in students]
print(passed_students)