I am writing a program to sort a list fo input strings (song names).
Those songnames contains latex chars like $\lambda$, which i want to
get sorted like ‘lambda’ instead, så i’m using a the ability to apply
a function to each element during sort. like this:
# -*- coding: UTF8 -*-
def conv( inp ):
if inp == '$\lambda$':
return 'lambda'
else:
return inp
mlist = []
mlist.append('martin')
mlist.append('jenny')
mlist.append('åse')
mlist.append('$\lambda$')
mlist.append('lambda')
mlist.append('\her')
print (mlist)
mlist = sorted(mlist, key=conv(str.lower))
print (mlist)
But for some reason, when i append the lambda sign or \her it converts it to \\her or $\\lambda$, can i prevent this?
No it doesn’t. What you’re seeing is the representation, which always doubles solo backslashes for clarity. If you print the actual strings instead you’ll see that they’re fine.