[pyar] Problema interesante: el anti-string
Roberto Alsina
ralsina en netmanagers.com.ar
Mie Ago 4 16:48:15 ART 2010
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?
More information about the pyar
mailing list