working with functions mapfilterreduceand list comprehensions map and filter python has built-in functions called map and filter that are used to apply functions to the contents of list they date back to before list comprehensions were part of pythonbut now list comprehensions can accomplish everything these functions can stillyou may occasionally see code using these functionsso it is good to know about them the map function takes two arguments-- function and an iterable--and it applies the function to each element of the iterablegenerating new iterable here is an example that takes list of strings returns list of the lengths of the strings the first line accomplishes this with mapwhile the second line uses list comprehensionsl list(map(len'this ''is '' ''test ']) [len(wordfor word in 'this ''is '' ''test ']the function filter takes function and an iterable and returns an iterable of all the elements of the list for which the function is true here is an example that returns all the words in list that have length greater than the first line uses filter to do thisand the second line does it with list comprehensionl list(filter(lambda xlen( )> 'this ''is '' ''test ']) [word for word in 'this ''is '' ''test 'if len(word)> here is one approach to finding the number of items in list that are greater than count= for in lif > count count here is second way using list comprehension similar to the filter functionlen([ for in if > ]the second way is both shorter and easier to understand reduce there is another functionreducethat applies function to the contents of list it used to be built-in functionbut in python it has also been moved to the functools module this function cannot be easily replaced with list comprehensions to understand itfirst consider simple example that adds up the numbers from to total for in range( , )total total the reduce function can be used to do this in single linetotal reduce(lambda ,yx+yrange( , )in generalreduce takes function and an iterableand applies the function to the elements from left to rightaccumulating the result as another simple examplethe factorial function could be implemented using reduce