[Python] Code Example 5 - Lambda & filter function (1)




[Source Code]

# Create a list of strings: fellowship
fellowship = ['frodo', 'samwise', 'merry', 'pippin', 'aragorn', 'boromir', 'legolas', 'gimli', 'gandalf']

# Use filter() to apply a lambda function over fellowship: result
result = filter(lambda member: len(member) > 6, fellowship)

# Convert result to a list: result_list
result_list = list(result)

# Print result_list
print(result_list)


[Output]==========================================


['samwise', 'aragorn', 'boromir', 'legolas', 'gandalf']



Comments

Popular posts from this blog

[Python] Code Example 1 - Dictionary

[Python] Code Example 2 - CSV to DataFrame