PROG0295 - Bilingual dictionary

A publisher has composed a bilingual dictionary English/Dutch. Every English word can have multiple Dutch translations, but the same word in Dutch could of course also be the translation of multiple English words. Now, the publisher wants to compose a bilingual dictionary Dutch/English. In order to cut costs, they hire you to write a computer program that can automatically convert the bilingual dictionary English/Dutch to a Dutch/English one.

Assignment

Write a function reverseTranslation to which a dictionary can be given that represents a bilingual dictionary. As an example, we use a dictionary English/Dutch. The keys of this dictionary are formed by the English words. The value that corresponds with a key is the list of possible translations in Dutch, represented as a list of strings.

As a result, the function must print a new dictionary, that also represents a bilingual dictionary and has the same format as the dictionary that was given to the function. Only, the words that printed as keys in this dictionary, are formed by the Dutch words that were given in the original dictionary. The value on which the Dutch words from this dictionary is portrayed, is formed by the list of English words of which the Dutch word is a possible translation. The words in this list must be in alphabetical order.

Example

>>> reverseTranslation({'tension': ['spanning'], 'voltage': ['spanning', 'voltage']})
{'spanning': ['tension', 'voltage'], 'voltage': ['voltage']}

>>> reverseTranslation({'soul': ['geest', 'gemoed', 'ziel'], 'spirit': ['geest']})
{'ziel': ['soul'], 'geest': ['soul', 'spirit'], 'gemoed': ['soul']}

>>> reverseTranslation({'wire': ['draad', 'metaaldraad'], 'thread': ['draad', 'garen']})
{'draad': ['thread', 'wire'], 'garen': ['thread'], 'metaaldraad': ['wire']}

Een uitgever heeft een vertaalwoordenboek Engels/Nederlands samengesteld. Elk Engels woord kan daarbij meerdere mogelijke vertalingen in het Nederlands hebben, maar hetzelfde woord in het Nederlands kan uiteraard ook de vertaling zijn van verschillende Engelse woorden. De uitgever wil nu ook een vertaalwoordenboek Nederlands/Engels samenstellen. Om kosten te besparen roepen ze je hulp in om een computerprogramma te schrijven dat automatisch het vertaalwoordenboek Engels/Nederlands kan omzetten in een vertaalwoordenboek Nederlands/Engels.

Opgave

Schrijf een functie omgekeerdeVertaling waaraan een dictionary kan doorgegeven worden dat een vertaalwoordenboek voorstelt. Bij wijze van voorbeeld gebruiken we een woordenboek Engels/Nederlands. De sleutels van deze dictionary worden gevormd door Engelstalige woorden. De waarde die correspondeert met een sleutel is de lijst van mogelijke vertalingen naar het Nederlands, voorgesteld als een lijst van strings.

De functie moet als resultaat een nieuwe dictionary teruggeven, die ook een woordenboek voorstelt en dus ook dezelfde vorm heeft als de dictionary die wordt doorgegeven. Alleen worden in de dictionary die wordt teruggegeven de sleutels gevormd door de Nederlandstalige woorden die in het meegeleverde woordenboek voorkomen. De waarde waarop het Nederlands woord in deze dictionary wordt afgebeeld, wordt gevormd door de lijst van Engelse woorden waarvan het Nederlandse woord een mogelijke vertaling vormt. De woorden in deze lijst moeten in alfabetische volgorde gerangschikt worden.

Voorbeeld

>>> omgekeerdeVertaling({'tension': ['spanning'], 'voltage': ['spanning', 'voltage']})
{'spanning': ['tension', 'voltage'], 'voltage': ['voltage']}

>>> omgekeerdeVertaling({'soul': ['geest', 'gemoed', 'ziel'], 'spirit': ['geest']})
{'ziel': ['soul'], 'geest': ['soul', 'spirit'], 'gemoed': ['soul']}

>>> omgekeerdeVertaling({'wire': ['draad', 'metaaldraad'], 'thread': ['draad', 'garen']})
{'draad': ['thread', 'wire'], 'garen': ['thread'], 'metaaldraad': ['wire']}

Added by:Peter Dawyndt
Date:2012-11-12
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:PY_NBC
Resource:None

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.