[pyar] Problema interesante: el anti-string
Nhomar Hernández
nhomar.hernandez en netquatro.com
Mie Ago 4 17:44:05 ART 2010
Yo todos los dias ordeno cosas ya que trabajo con un ERP..... y este es mi
manual de referencia...
http://wiki.python.org/moin/HowTo/Sorting/#OperatorModuleFunctions
Creas tu metodo que crea en vivo la clave de ordenamiento y listo..... y lo
hago con objetos bien complejos...
Saludos.
2010/8/4 Roberto Alsina <ralsina en netmanagers.com.ar>
> 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? ;-)
> _______________________________________________
> pyar mailing list pyar en python.org.ar
> http://listas.python.org.ar/listinfo/pyar
>
> PyAr - Python Argentina - Sitio web: http://www.python.org.ar/
>
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20100804/e9e2faba/attachment.html>
More information about the pyar
mailing list