Coding challenge: Optimise a custom string encoding

Lele Gaifax lele at metapensiero.it
Tue Aug 19 06:00:45 EDT 2014


Alex Willmer <alex at moreati.org.uk> writes:

> def plus_encode(s):
>     """Encode a unicode string with only ascii letters, digits, _, -, @, +
>     """
>     bytemap_ = bytemap
>     s_utf8 = s.encode('utf-8')
>     return ''.join([bytemap[byte] for byte in s_utf8])

Minor nit: you defined a local alias for bytemap for faster access, but
didn't actually used it.

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele at metapensiero.it  |                 -- Fortunato Depero, 1929.




More information about the Python-list mailing list