List Comprehension in python
# list Comperhension = a way to create a new list with less syntax
# can mimic certain lambda functions easier to read
# list = [expersion for item in iterable]
# sqare = []
# for i in range(1,11):
# sqare.append(i*i)
# print(sqare)
# sqares=[i*i for i in range(1,11)]
# print(sqares)
passing = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
passing.reverse()
# passed = list(filter(lambda x:x >= 33, passing))
# print(passed)
# passed = [i for i in passing if i >=33]
# print(passed)
passed = [i if i >= 33 else "failed" for i in passing]
print(passed)
Comments
Post a Comment