You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# In Python, map and filter are built-in functions that allow you to apply a function to each element of an iterable (like a list) and filter elements based on a condition, respectively.
def checkEven(num):
return num%2 == 0
lst = [1,2,3,4,5,6,7,89]
# Map Syntax
# map(function, iterable)
ans = list(map(checkEven,lst))
print(ans)
# filter Syntax
# filter(function, iterable)
ans = list(filter(checkEven,lst))
print(ans)
# Example - 2
# Write a Program to check a string starts with A, a, S, or r.
check = lambda s : (s.startswith("A") or s.startswith("a") or s.startswith("S") or s.startswith("r"))