-
Notifications
You must be signed in to change notification settings - Fork 0
/
listComprehension.py
23 lines (19 loc) · 1.03 KB
/
listComprehension.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# list comprehension = 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)
# squares = [i*i for i in range(1,11)]
# print(squares)
# --------------------------------------------------------------
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)
# --------------------------------------------------------------