Answers for "python filter from list"

9

filter list with python

scores = [70, 60, 80, 90, 50]
filtered = filter(lambda score: score >= 70, scores)

print(list(filtered))

# Output:
[70, 80, 90]
Posted by: Guest on January-12-2021
0

filtering a list

scores = [70, 60, 80, 90, 50]
filtered = filter(lambda score: score >= 70, scores)

print(list(filtered))
Code language: Python (python)
Posted by: Guest on October-04-2021
-1

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
Posted by: Guest on August-11-2020

Code answers related to "python filter from list"

Python Answers by Framework

Browse Popular Code Answers by Language