Saturday, 23 February 2019

python filter, map

items = [
    ('product1', 10),
    ('product2', 9),
    ('product3', 12),
]

filtered = list(filter(lambda item: item[1] >= 10, items))
print(filtered)

[('product1', 10), ('product3', 12)]

items = [
    ('product1', 10),
    ('product2', 9),
    ('product3', 12),
]

prices = list(map(lambda item: item[1], items))
print(prices)

[10, 9, 12]

No comments:

Post a Comment