filter list with python
scores = [70, 60, 80, 90, 50]
filtered = filter(lambda score: score >= 70, scores)
print(list(filtered))
# Output:
[70, 80, 90]
filter list with python
scores = [70, 60, 80, 90, 50]
filtered = filter(lambda score: score >= 70, scores)
print(list(filtered))
# Output:
[70, 80, 90]
filtering a list
scores = [70, 60, 80, 90, 50]
filtered = filter(lambda score: score >= 70, scores)
print(list(filtered))
Code language: Python (python)
python - filter function
# Filter function
def with_s(student):
return student.startswith('s')
students = ['sarah', 'mary', 'sergio', 'lucy'] # define a list
s_filter = filter(with_s, students) # filter() returns true or false
print(next(s_filter)) # filter() returns a generator
print(list(s_filter)) # give all elements of the generator
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us