City Dancers

We have information about swing dancers in two dictionaries:

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

  • The second 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, to make it simple, consists of two str with the name and the city of the dancer.

For example,


>>> dni_dan_D = {
... '678S': ['Blues', 'Jazz', 'Lindy_Hop', 'Balboa', 'Rock&Roll'],
... '557D': ['Rock', 'Blues', 'Lindy_Hop',],
... '778K': ['Shag', 'Balboa', 'Lindy_Hop'],
... '441K': ['Lindy_Hop'],
... '779N': ['Balboa', 'Lindy_Hop', 'Blues', 'Rock&Roll', 'WCS'],
... '666Z': ['Jazz', 'Lindy_Hop'],
... '101A': ['Lindy_Hop'],
... }

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

You are required to implement the following functions in the module city_dancers.py (file city_dancers.py). Bear in mind that the fist function is 80% and the second is 20%:

Generate Dancers dict

gen_city_dancers_D(dni_dan_D, dni_D, d)

such that given

  • dni_dan_D a dict as described above,

  • dni_D a dict as described above,

  • d a name of a swing dance (str),

returns

a dict where the keys are city names that are associated to a list of the names of the dancers in that city that like to dance d. In the event that a dancer in dni_dan_D that dances d does not appear in dni_D, their DNI will be included in a list of DNIs associated with the Unknown key. If this case never occurs then the Unknown will not appear in the resulting dictionary.

Here is an example doctest:


>>> ddan = gen_city_dancers_D(dni_dan_D, dni_D, 'Blues')
>>> ddan_corr = {'BCN': ['Inma', 'Adamo'], 'St.Cugat': ['Zoe']}
>>> if ddan != ddan_corr:
...     print(ddan)
...     print(ddan_corr)
... else:
...     True
True

>>> ddan = gen_city_dancers_D(dni_dan_D, dni_D, 'Lindy_Hop')
>>> ddan_corr = {
... 'BCN': ['Inma', 'Eva', 'Adamo'],
... 'St.Cugat': ['Zoe', 'Xavier'],
... 'Unknown': ['666Z', '101A'],
... }
>>> if ddan !=  ddan_corr:
...     print(ddan)
...     print(ddan_corr)
... else:
...     True
True

>>> gen_city_dancers_D(dni_dan_D, dni_D, 'Salsa')
{}

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

Sort Dancers lists

ord_city_dancers_D(cd_D)

such that given a dict cd_D as the one produced by the previous function gen_city_dancers_D

modifies

cd_D such that all the lists of names of dancers are alphabetically ordered.

Here is an example doctest:

>>> from city_dancers import ord_city_dancers_D

>>> d = {'BCN': ['Inma', 'Adamo'], 'St.Cugat': ['Zoe']}
>>> ord_city_dancers_D(d)
>>> d == {'BCN': ['Adamo', 'Inma'], 'St.Cugat': ['Zoe']}
True

>>> d = {'BCN': ['Inma', 'Eva', 'Adamo'], 'St.Cugat': ['Zoe', 'Xavier'], 'Unknown': ['666Z', '101A']}
>>> ord_city_dancers_D(d)
>>> d == {'BCN': ['Adamo', 'Eva', 'Inma'], 'St.Cugat': ['Xavier', 'Zoe'], 'Unknown': ['101A', '666Z']}
True

>>> d = {}
>>> ord_city_dancers_D(d)
>>> d == {}
True

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