Dancers¶
We have information about swing and blues dancers in two dictionaries:
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
dictdni_D and dni_dan_D as described abovereturns a
dictwhere 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 atuplewith two components: the dancer name, and the city of residence. In the event that a dni indni_dan_Dis not a key indni_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
dictas the one produced by the previous functionmodifies 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.