avatar Bite 286. Decompress

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.

Login and get coding
go back Intermediate level
Bitecoin 3X

17 out of 18 users completed this Bite.
Will you be Pythonista #18 to crack this Bite?
Resolution time: ~23 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 4.0 on a 1-10 difficulty scale.
» Up for a challenge? 💪

We use Python 3.8