[pyar] Problema interesante: el anti-string

Roberto Alsina ralsina en netmanagers.com.ar
Mie Ago 4 17:05:55 ART 2010


On Wednesday 04 August 2010 16:48:36 Pablo Ziliani wrote:
> 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  :)

Con 16MB tengo el mas grande posible, no? ;-)



More information about the pyar mailing list