Fauna of “Els Ports de Beseit”¶
We have been given a text about the fauna of “Els Ports de Beseit”,
where there are animal names in its vulgar version (eg goats, wild
boars, …). It is also available a dictionary where each pair is
formed by the vulgar name (key) and the scientific name (value) of an
animal. Text words in the given text are always separated by
spaces and the vulgar names of animals always appear in plural
both in the given text and in the dictionary. Save the following
function into the file fauna.py:
Write the function scientific() that takes a text
(str) and a dictionary (dict) as described, and
returns the same text (str) as the given one but in which
after each vulgar name we must include the corresponding scientific
between parenthesis. Words in this new text are separated by a single
space. Example:
>>> textini = """\ ... A large herd of goats jumps across the massif with an important \ ... population of five thousand units and that constitutes \ ... the most emblematic species of Els Ports. There are also wild_boars \ ... scattered throughout the mountain range. Sadly, wolves were extinguished \ ... for over 100 years but there are foxes which are smaller and not as bad. \ ... We can see eagles flying in many places and vultures can also be seen. \ ... Among the rodents there are squirrels \ ... and there are also reptiles like adders among others.""" >>> d_animals = {'goats': 'capra hispanica', 'wild_boars': 'sus scrofa', ... 'wolves': 'canis lupus', 'foxes': 'vulpes vulpes', ... 'eagles': 'aguila chrysaetos', 'vultures': 'gyps fulvus', ... 'squirrels': 'sciurus vulgaris', 'adders': 'vipera latasti'} >>> r = scientific (textini, d_animals) >>> if r != """\ ... A large herd of goats (capra hispanica) jumps across the massif with an \ ... important population of five thousand units and that constitutes the most \ ... emblematic species of Els Ports. There are also wild_boars (sus scrofa) \ ... scattered throughout the mountain range. Sadly, wolves (canis lupus) \ ... were extinguished for over 100 years but there are foxes (vulpes vulpes) \ ... which are smaller and not as bad. \ ... We can see eagles (aguila chrysaetos) flying in many places \ ... and vultures (gyps fulvus) can also be seen. \ ... Among the rodents there are squirrels (sciurus vulgaris) \ ... and there are also reptiles like adders (vipera latasti) among others.""": ... print(r)
Note
You can download the file with tests test-fauna.txt.
Solution
You have a solution in file fauna.py.