[pyar] Problema interesante: el anti-string
Pablo Ziliani
pablo en kultroom.com
Mie Ago 4 16:17:40 ART 2010
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')]
More information about the pyar
mailing list