Listing and Filtering Town Temperatures

Let’s consider a list with information regarding the weather temperatures measured in several towns. The information for each town is represented as a 4-component tuple with the following fields:

  • an identification number (int)

  • the town name (str)

  • a list of temperatures (list of float)

  • the updated flag (bool): True is the info is up to date and False otherwise.

For example:


>>> l = [
... (1, 'Vilanova', [23.0, 20.0, 25.0, 28.0], True), 
... (2, 'Vilademuls', [24.0, 25.0, 21.0], False), 
... (3, 'Vilana', [16.5, 18.5], True), 
... (4, 'Vilamalla', [10.0, 20.0, 13.5, 28.0], False), 
... (5, 'Vilafranca', [27.5, 13.5, 28.0], True), 
... (6, 'Vila', [13.5, 26.5, 28.0], True)
... ]

You are required to deliver the following functions in the module list_town_temp (file list_town_temp.py):


The function:

list_himax_town(tL, ref)

such that

given

returns a new list with the names of the towns whose maximum temperature is higher or equal than ref. The names must be alfabetically ordered.

For example:


>>> list_himax_town(l, 30.0)
[]

>>> list_himax_town(l, 28.0)
['Vila', 'Vilafranca', 'Vilamalla', 'Vilanova']

>>> list_himax_town(l, 25.0)
['Vila', 'Vilademuls', 'Vilafranca', 'Vilamalla', 'Vilanova']

>>> list_himax_town(l, 18.0)
['Vila', 'Vilademuls', 'Vilafranca', 'Vilamalla', 'Vilana', 'Vilanova']

Doctests are available in the list_himax_town.test file.

Warning

The input list must remain intact.


The function:

list_hiavg_town(tL, ref)

such that

given

returns a new list with the towns whose average temperature is higher or equal than ref and the temperatures are up-to-date. For each town fulfilling this condition the list must have a 2-place tuple with:

  • The town name.

  • The average rounded to 2 decimals.

The list must be alfabetically ordered by the town name.

For example:


>>> list_hiavg_town(l, 25.0)
[]

>>> list_hiavg_town(l, 24.0)
[('Vilanova', 24.0)]

>>> list_hiavg_town(l, 23.0)
[('Vilafranca', 23.0), ('Vilanova', 24.0)]

>>> list_hiavg_town(l, 22.0)
[('Vila', 22.67), ('Vilafranca', 23.0), ('Vilanova', 24.0)]

>>> list_hiavg_town(l, 15.0)
[('Vila', 22.67), ('Vilafranca', 23.0), ('Vilana', 17.5), ('Vilanova', 24.0)]

Doctests are available in the list_hiavg_town.test file.

Warning

The input list must remain intact.