Message Coder X13025


Statement
 

pdf   zip

thehtml

A message encoding of a given non-empty string s is a dictionary cs which contains, for each unique symbol in s, an ordered list of the positions where that symbol occurs within s.

Implement the function coder(s) such that, given the message s, it returns a dictionary where the keys are the unique symbols in s, and the values are ordered lists containing the positions at which each symbol appears in s.

Sample session
>>> d_salida = {'m': [0], 'i': [1, 14, 16], 's': [2, 3], 'a': [4, 18], 't': [5],
... 'g': [6], 'e': [7, 9], 'p': [8], 'r': [10, 19], 'c': [11, 17], 'o': [12],
... 'd': [13], 'f': [15]}
>>> if d_salida != coder("missatgepercodificar"): print(d_salida)
>>> d_salida = {'h': [0, 4, 8], 'o': [1, 5, 9], 'l': [2, 6, 10], 'a': [3, 7, 11]}
>>> if d_salida != coder("holaholahola"): print(d_salida)
>>> d_salida = {'k': [0, 1, 2]}
>>> if d_salida != coder("kkk"): print(d_salida)
>>> d_salida = {'a': [0, 2, 4, 10, 13, 15, 19], 'x': [1, 6, 9, 16], 's': [3], 'z': [5],
... 'i': [7], 'n': [8, 11], 'c': [12, 14], 't': [17], 'l': [18]}
>>> if d_salida != coder("axasazxinxancacaxtla"): print(d_salida)
>>> d_salida = {'f': [0], 'e': [1, 18], 'l': [2], 'i': [3, 8], 'z': [4], 'n': [5 ],
... 'a': [6, 10], 'v': [7], 'd': [9, 11], 'y': [12], 'p': [13, 17], 'r': [14, 19],
... 'o': [15, 20], 's': [16], '2': [21], '0': [22], '1': [23], '8': [24]}
>>> if d_salida != coder("feliznavidadyprospero2018"): print(d_salida)
Information
Author
Professors Informàtica EEBE
Language
English
Other languages
Catalan Spanish
Official solutions
Python
User solutions
Python