filter function py code example
Example: 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