Bags

A shop represents a bag model with a tuple of 3 elements: the first one is the name of the model (str) and the other two are, respectively, the number of outer and inner pockets in this bag model (int). Write the function bags() that takes a list of bags (a list of tuples), and returns a dictionary (dict) with the following characteristics: the key is a tuple with two integers, (number of outer pockets, number of inner pockets), and the value is a list with the names of those models that have these number of outer and inner pockets, ordered in the same way as in the given list of tuples. Models with no pockets must not appear in the dictionary. Save this function into the file bags.py. Examples:

>>> bagslst = [('Nile', 0, 1), ('Albion', 0, 0), ('BR18', 1, 1),
... ('Nicola', 2, 1), ('Dahlia',1, 0), ('Retro', 0, 0), ('MonSac', 2, 1),
... ('Eli', 2, 1), ('DotCom', 0, 1), ('Estivo', 1, 1)]
>>> d = bags(bagslst)
>>> if d != {(0, 1): ['Nile', 'DotCom'], (1, 0): ['Dahlia'],
...   (1, 1): ['BR18', 'Estivo'], (2, 1): ['Nicola', 'MonSac', 'Eli']}:
...    print(d)

Note

You can download the file with tests test-bags.txt.

Solutions

A solution is provided in file bags.py.