[pyar] Problema interesante: el anti-string

Pablo Ziliani pablo en kultroom.com
Mie Ago 4 16:48:36 ART 2010


Roberto Alsina wrote:
> On Wednesday 04 August 2010 16:41:27 Pablo Ziliani wrote:
>   
>>  >>> S1 = [u'papa', u'foo', u'pepe', u'bar', u'python']
>>  >>> chars = sorted(set(''.join(S1)))
>>  >>> antichars = dict(zip(chars, reversed(chars)))
>>  >>> S = [(word, u''.join(antichars[char] for char in word)) for word in
>> S1] >>> sorted(S, key=lambda x:x[0])
>> [(u'bar', u'tye'), (u'foo', u'phh'), (u'papa', u'fyfy'), (u'pepe', 
>> u'frfr'), (u'python', u'fabohn')]
>>  >>> sorted(S, key=lambda x:x[1])
>> [(u'python', u'fabohn'), (u'pepe', u'frfr'), (u'papa', u'fyfy'), 
>> (u'foo', u'phh'), (u'bar', u'tye')]
>>     
>
> Interesante :-)
>
> Pero si quiero agregar un nuevo string tengo que regenerar antichars, no?

a no ser que te generes antes un the_worldst_biggest_mega_antichars  :)



More information about the pyar mailing list