Pybites Logo

Gourmets' nightmare

Level: Intermediate (score: 3)

Many gourmets struggle to find the perfect pairing of wines and cheeses. A number of considerations are relevant, each of which creates a unique combination. Finding the perfect match is a life long pursuit.

For the purposes of this bite, you will pair cheese and wines by the similarities of their names. We've helpfully provided a name similarity function, defined as:

             sum of values of intersection of char counters of names
similarity = ―――――――――――――――――――――――――――――――――――――――――――――――――――――――
                   1 + square of length difference of both words

Upper and lower case letters are ignored in the summing process.

Space " ", dash "-", and apostrophe "'" are considered valid characters.

Examples:
Example 1
'house' 'mouse'            -> {'e': 1, 'o': 1, 's': 1, 'u': 1}  -> 4 / (1 + pow(5 - 5),2)) = 4
'parapraxis' 'explanation' -> {'a': 2, 'i': 1, 'p': 1, 'x': 1}  -> 5 / (1 + pow(10 - 11),2) = 2.5
'parapraxis' 'parallax'    -> {'a': 3, 'p': 1, 'r': 1, 'x': 1}  -> 6 / (1 + (10 - 8)**2 ) = 1.2
'roosters-do-sound' 'cocka-doodle-doo' -> {'-': 2, 'd': 2, 'e': 1, 'o': 4} -> 9 / (1 + pow(17-16),2) = 4.5
'Cabernet sauvignon' 'Dorset Blue Vinney' ->  
                              {'e': 2, 'n': 2, 'o': 1, 'r': 1, 's': 1, 't': 1, ' ': 1, 'b': 1, 'u': 1, 'v': 1, 'i': 1} -> 13 / (1 + pow(18 - 18),2) = 13

Three wine lists are provided; red, white, sparkling.

Pair the wine with the forty-three cheeses mentioned in the Monty Python's Flying Circus sketch "Cheese Shop".


Tasks

  1. Complete the function best_match_per_wine() which returns the best scored wine-cheese pair. Matching can be for a certain wine type (i.e. red, white, sparkling) or for all types. Raise ValueError for wines that do not appear in the lists of known wines.

     

  2. Complete the function match_wine_5cheeses() which returns a sorted list of wines, where for each wine are listed 5 best matching cheeses.

All types of wines (red, white, and sparkling) are included.

Lists of cheeses are sorted by descending similarity score and then ascending alphabetical order.

Output example:

[('Barbera', ['Cheddar', 'Gruyère', 'Boursin', 'Parmesan', 'Liptauer']),
..
('Zinfandel', ['Caithness', 'Bel Paese', 'Ilchester', 'Limburger', 'Lancashire'])]