Pybites Logo

Decompress

Level: Intermediate (score: 3)

Write a function, called decompress(), that accepts a string and a dictionary as input.

The dictionary maps special character strings to sequences of characters.

The function goes through the argument string and if the character is in the dictionary, it converts it to the corresponding character sequence.  

Example:

>>> table = {'$': 's',

             '%': 'y',

             '/': 't'

             }

>>> decompress('P%Bi/e$', table) 
'PyBites'

Note that a special character may map to a sequence of characters that ALSO has a special character in it.  

Example:

>>> table = {'*': 'c',

             '#': '00',

             '$': '*y',

             }

>>> decompress('$3#', table)
'cy300'

For example the symbol table maps $ to the string *y and * maps to c.