Login and get codingWrite 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 toc
.
50 out of 51 users completed this Bite.
Will you be the 51st person to crack this Bite?
Resolution time: ~29 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 4.0 on a 1-10 difficulty scale.
» Up for a challenge? 💪