Dancers

We have information about swing and blues dancers in two dictionaries:

  • The first one, let’s call it dni_D, associates to the DNI (str) of a dancer, a list with the personal info of the dancer, which consists of two str: the name, and the city of residence.

  • The second one, let’s call it dni_dan_D, associates the DNI (str) of a dancer to the list of dances he/she likes.

For example,


>>> dni_D = {
... '678S': ('Inma', 'BCN'),
... '557D': ('Zoe', 'St.Cugat'),
... '778K': ('Eva', 'BCN'),
... '441K': ('Xavier', 'St.Cugat'),
... '779N': ('Adamo', 'BCN'),
... }
>>> dni_dan_D = {
... '678S': ['Blues', 'Lindy_Hop'],
... '557D': ['Lindy_Hop', 'Blues'],
... '666Z': ['Lindy_Hop'],
... '779N': ['Blues'],
... }

Notice that the dancers represented in these two dict are not necessarily the same.

Implement the following functions in the module dancers.py (file dancers.py):

Note

The grade weight of the fist function is 80% and the second is 20%.

Generate Dances Dict

gen_dances_D(dni_D, dni_dan_D)

such that

given the dict dni_D and dni_dan_D as described above

returns a dict where the keys are the dance names in dni_dan_D and the value for each dance is a list of the dancers that like that dance in t he following format: for each dancer, there is a tuple with two components: the dancer name, and the city of residence. In the event that a dni in dni_dan_D is not a key in dni_D, then this tuple will be composed of its DNI and the '?' string.

Here is an example:


>>> ddan_corr = {
... 'Blues': [('Inma', 'BCN'), ('Zoe', 'St.Cugat'), ('Adamo', 'BCN')],
... 'Lindy_Hop': [('Inma', 'BCN'), ('Zoe', 'St.Cugat'),  ('666Z', '?')],
... }

Notice that, since DNI '666Z' is not found in dni_D, it appears in the resulting dict as the tuple ('666Z', '?') in the list associated to 'Lindy_Hop'.

You will find more tests in the gen_dances_D-test.txt file.

Sort Dances Dict

sort_dances_D(D)

such that

given D, a dict as the one produced by the previous function

modifies D such that all the lists of tuples with dancers info are ordered as follows: firstly by alphabetically by its city, and secondly, those from the same city are alphabetically ordered by its name.

Here is an example doctest:


>>> D = {
... 'Blues': [('Inma', 'BCN'), ('Zoe', 'St.Cugat'), ('Adamo', 'BCN')],
... 'Lindy_Hop': [('Zoe', 'St.Cugat'), ('Inma', 'BCN'), ('Xavier', 'St.Cugat'),  ('666Z', '?')],
... }
>>> Dcorr = {
... 'Blues': [('Adamo', 'BCN'), ('Inma', 'BCN'), ('Zoe', 'St.Cugat')],
... 'Lindy_Hop': [('666Z', '?'), ('Inma', 'BCN'), ('Xavier', 'St.Cugat'), ('Zoe', 'St.Cugat')],
... }

You will find more tests in the sort_dances_D-test.txt file.