Little Lena's book of puzzles contains the following challenge. The goal is to connect each fruit with the corresponding color.

colorful fruits
Connect each fruit with the corresponding color.

Because little Lena is a bit stubborn (or because she's simply too young), she takes pleasure in randomly connecting the fruits with the colors. However, she always makes sure that each fruit is connected with at most one color and that each color is connected with at most one fruit.

Assignment

Write a function

combine(colors, fruits[, number])

that takes two sequences (list or tuple) of words (str). The function also has a third optional parameter amount that may take an integer (int). The function must return a list of strings (str), whose elements are formatted as a word1 word2 with word1 a randomly chosen word from the first sequence and word2 a randomly chosen word from the second sequence. The function must make different combinations until all words from one of the given sequences have been used, taking into account that each word from a sequence can be used at most once. If a third argument is given, no more than the given amount of combinations should be included in the returned list.

Tip

Take a look at the functions choice and sample in the random module from the The Python Standard Library1.

Example

>>> colors = ['purple', 'yellow', 'green']
>>> fruits = ('grape', 'banana', 'apple')
>>> combine(colors, fruits)
['a purple grape', 'a green banana', 'a yellow apple']
>>> combine(colors, fruits)
['a purple grape', 'a green apple', 'a yellow banana']
>>> combine(colors, fruits)
['a purple apple', 'a yellow grape', 'a green banana']
>>> combine(colors, fruits, amount=1)
['a purple grape']
>>> combine(colors, fruits, amount=2)
['a yellow apple', 'a green banana']
>>> combine(colors, fruits, amount=4)
['a yellow banana', 'a green grape', 'a purple apple']