Write the function map
using accumulate
. Name your function my_map
.
Write a function called remove_duplicates
that takes in a list as its only argument and returns a list with duplicate elements removed. The order of the elements in the returned list does not matter. Use filter
in your function.
Our friend Louis Reasoner has a pocket full of change. He wants to buy a snack that will cost him x cents, and he wants to know all the ways in which he can use his change to make up that amount. Please help him in writing a function which takes as parameters the amount x and a list of all the coins Louis has in his pocket, and returns a list of lists, such
that each sub-list of the result contains a valid combination to make up x. A combination may appear more than once, since it may be using different coins of the same denomination. Help Louis by filling in the ellipses ...
in his incomplete solution:
Write a function called remove_duplicates
that takes in a list as its only argument and returns a list with duplicate elements removed. The order of the elements in the returned list does not matter. Use accumulate
in your function.
In this question, lists represent sets. Each element of the set appears exactly once in its list representation, and the order does not matter. So the list list(1, 2, 3)
represents the same set as the list list(3, 2, 1)
.
In this question, you are supposed to compute all subsets of a given set. Your function subsets
takes as argument a list, representing the given set, and needs to return a list of lists, each representing a unique subset of the given set.
A permutation of a list s is a list with the same elements as s, but in a possibly different order. For example, the list list(3,1,2)
is a permutation of list(1,2,3)
. Write a function permutations
that takes a list s as argument and returns a list of all permutations of s.