[pyar] Problema interesante: el anti-string
Roberto Alsina
ralsina en netmanagers.com.ar
Mie Ago 4 16:31:20 ART 2010
On Wednesday 04 August 2010 16:17:40 Pablo Ziliani wrote:
> Roberto Alsina wrote:
> > Dado un string S, crear una funcion f tal que S1>S2 => f(S1) < f(S2)
>
> o sea, algo así pero donde a[1] sea un caracter razonable, no?
>
> >>> a = ['papa', 'foo', 'pepe', 'bar', 'python']
> >>> m = ord(max(''.join(a)))
> >>> b = [(i, ''.join(chr(m - ord(j)) for j in i)) for i in a]
> >>> b
> [('papa', '\t\x18\t\x18'), ('foo', '\x13\n\n'), ('pepe',
> '\t\x14\t\x14'), ('bar', '\x17\x18\x07'), ('python',
> '\t\x00\x05\x11\n\x0b')]
> >>> sorted(b, key=lambda x:x[0])
> [('bar', '\x17\x18\x07'), ('foo', '\x13\n\n'), ('papa', '\t\x18\t\x18'),
> ('pepe', '\t\x14\t\x14'), ('python', '\t\x00\x05\x11\n\x0b')]
> >>> sorted(b, key=lambda x:x[1])
> [('python', '\t\x00\x05\x11\n\x0b'), ('pepe', '\t\x14\t\x14'), ('papa',
> '\t\x18\t\x18'), ('foo', '\x13\n\n'), ('bar', '\x17\x18\x07')]
Esa es la idea :-D
Funciona con unicode?
More information about the pyar
mailing list