Artists Tours

We have the programs of the music festival are stored in a dictionnary, let’s call it fest_D, where the key is the name of the festival (str) and the value is a list of the “days” of the festival. Each day is in turn a list where the first component is the calendar date (which is a 3-int tuple: the year, the month and the day) and the rest are the artist names (str) scheduled to perform that date.

See the following example:

>>> fest_D = {
... 'Canet Rock': [ 
... [(2023,7,3), 'Stay Homas', 'Suu', 'Oques Grasses'] ],
... 'Vida': [
... [(2023,7,1), 'Vetusta Morla', 'Suu'],
... [(2023,7,2), 'Nathy Peluso', 'Stay Homas'],
... [(2023,7,3), 'Love of Lesbian', 'Clara Peya'] ],
... 'Luz de Gas': [ 
... [(2023,6,18), 'Clara Peya'],
... [(2023,6,25), 'Bet'],
... [(2023,7,2), 'Suu'] ]
... }

Notice that Canet Rock festival takes only one day whereas the Vida festival takes three days: 2023/7/1, 2023/7/2 and 2023/7/3, and several artists are scheduled each of they. Also we know that an artist is scheduled for at most one gig for festival.

Our purpose is, given a dict with the programs of a number of music festivals and a list of artist names (str), to generate for each of those artists its tour of gigs in those festivals. Namely, we want to generate a dict, let’s call it tour_D, whose keys are the artists names and the associated value is an ordered list of the gigs for that artist, where each gig is a 2-value tuple with the date of the gig (which in turn is a 3-int tuple) and the name of the festival (str). The order of the list is increasing by date. For example:


>>> art_L = ['Stay Homas', 'Suu','Zoo']
>>> tour_D = gen_tour_D(fest_D, art_L)
>>> if tour_D != {
... 'Stay Homas': [((2023,7,2), 'Vida'), ((2023,7,3), 'Canet Rock')],
... 'Suu': [((2023,7,1), 'Vida'), ((2023,7,2), 'Luz de Gas'), ((2023,7,3), 'Canet Rock')],
... 'Zoo': []
... }:
...     print(tour_D)
... else:
...     True
True

>>> art_L = ['Peret']
>>> gen_tour_D(fest_D, art_L)
{'Peret': []}


Now, to solve this problem it is mandatory to create the module tours (file tours.py) and write the functions specified in the following steps:

Step #1. Write a function to find an artist in a list of days:

find_art(art, fest_dates_L)

such that given

  • art is a str with the name of an artist

  • fest_dates_L is a list “dates” as the ones in the values of dict fest_D described above

returns either a 3-int tuple with the first date when that artist is scheduled or the empty tuple () is the artist does not appear in any sublist.

For example:

>>> from tours import find_art

>>> fest_dates_L = [
... [(2021,7,1), 'Vetusta Morla', 'Suu'],
... [(2021,7,2), 'Nathy Peluso', 'Stay Homas'],
... [(2021,7,3), 'Love of Lesbian', 'Clara Peya'] ]

>>> find_art('Suu', fest_dates_L)
(2021, 7, 1)
>>> find_art('Stay Homas', fest_dates_L)
(2021, 7, 2)
>>> find_art('Bet', fest_dates_L)
()

Test sets are available in the file find_art-test.txt.


Step #2. Write and test the following function to construct a dict of not necessarily ordered tours, by calling the previous function:

cnst_tour_D(fest_D, art_L)

such that given

  • fest_D a dict as described above

  • art_L is a list of str with artist names

returns a tour_D dict as described above where the tours associated with each artist are not necessarily ordered.

For example:


>>> tour_D = cnst_tour_D(fest_D, ['Oques Grasses', 'Bet'])
>>> if tour_D == {
... 'Oques Grasses': [((2023, 7, 3), 'Canet Rock')],
... 'Bet': [((2023, 6, 25), 'Luz de Gas')]
... }:
...     True
... else:
...     print(tour_D)
True

>>> tour_D = cnst_tour_D(fest_D, ['Stay Homas', 'Suu', 'Zoo'])
>>> if tour_D == {
... 'Stay Homas': [((2023, 7, 3), 'Canet Rock'), ((2023, 7, 2), 'Vida')],
... 'Suu': [((2023, 7, 3), 'Canet Rock'),  ((2023, 7, 1), 'Vida'), ((2023, 7, 2), 'Luz de Gas')],
... 'Zoo': []
... }:
...     True
... else:
...     print(tour_D)
True

>>> cnst_tour_D(fest_D, ['Peret'])
{'Peret': []}

Test sets are available in the file cnst_tour_D-test.txt.


Step #3. Write and test a function to order the tours:

sort_tour_D(tour_D)

such that given

  • tour_D a dict as described above,

modifies it by ordering increasingly by date, every tour associated with its artists.

For example:

>>> from tours import sort_tour_D

>>> tour_D = {
... 'Stay Homas': [((2023, 7, 3), 'Canet Rock'), ((2023, 7, 2), 'Vida')],
... 'Suu': [((2023, 7, 3), 'Canet Rock'),  ((2023, 7, 1), 'Vida'), ((2023, 7, 2), 'Luz de Gas')],
... 'Zoo': []}

>>> sort_tour_D(tour_D)

>>> if tour_D != {
... 'Stay Homas': [ ((2023,7,2), 'Vida'), ((2023,7,3), 'Canet Rock') ],
... 'Suu': [ ((2023,7,1), 'Vida'), ((2023,7,2), 'Luz de Gas'), ((2023,7,3), 'Canet Rock') ],
... 'Zoo': []
... }:
...     print(tour_D)
... else:
...     True
True

Test sets are available in the file sort_tour_D-test.txt.


Step #4. Finally write and test the function

gen_tour_D(fest_D, art_L)

such that given

  • fest_D a dictionnary as describe above

  • art_L is a list of str with artist names

returns a tour_D dict whose keys are the artists in art_L and the associated value is an ordered list of the artist’s gigs as described above. The order of all the gigs list is increasing by date.

See the example at the beginning of this statement.

Test sets are available in the file gen_tour_D-test.txt.