--Originally published at Elu's Blog
26. Using the higher order function reduce()
, write a function max_in_list()
that takes a list of numbers and returns the largest one. Then ask yourself: why define and call a new function, when I can just as well call the reduce()
function directly?
27. Write a program that maps a list of words into a list of integers representing the lengths of the correponding words. Write it in three different ways: 1) using a for-loop, 2) using the higher order function map()
, and 3) using list comprehensions.
28. Write a function find_longest_word()
that takes a list of words and returns the length of the longest one. Use only higher order functions.
29. Using the higher order function filter()
, define a function filter_long_words()
that takes a list of words and an integer n
and returns the list of words that are longer than n
.
30. Represent a small bilingual lexicon as a Python dictionary in the following fashion {"merry":"god", "christmas":"jul", "and":"och", "happy":gott", "new":"nytt", "year":"år"}
and use it to translate your Christmas cards from English into Swedish. Use the higher order function map()
to write a function translate()
that takes a list of English words and returns a list of Swedish words.