## Re: [Jython-users] Customized list sorting

 Re: [Jython-users] Customized list sorting From: - 2007-04-24 05:47:05 ```Sorry for the disturbance. I looked at it again and it was a flaw in my code. It's fixed now =/ On 4/24/07, astigmatik@... wrote: > Using Jython2.2b1, I tried to implement my own sorting. The order of > precedence is: All strings that begin with @ are the "highest" (i.e. > they are top of the list), followed by %, then by +, and then by > "{}[]`\^_|", and only then "a-z" (or alphabetical). > ```

 [Jython-users] Customized list sorting From: - 2007-04-24 03:44:27 ```Using Jython2.2b1, I tried to implement my own sorting. The order of precedence is: All strings that begin with @ are the "highest" (i.e. they are top of the list), followed by %, then by +, and then by "{}[]`\^_|", and only then "a-z" (or alphabetical). This forces strings that begin with "{" or "}" to appear before strings that begin with "a-z". Below is the code that I use. But I'm wonder why the word "lag" is shown *before* the strings that begin with "{" or "}". The sorted list comes out like this: .... more items here... `wall lag {hall }baby all bring Why is the "lag" before "{hall"? But "all" and "bring" are below "}baby" (which is what I expected). Shouldn't "lag" be the last in the list? Here is my exact snippet: # Begin def ircnick_sort(a, b): special_chars = "{}[]`\^_|" if a[0] == '@': if b[0] == '@': return ircnick_sort(a[1:], b[1:]) else: return -1 elif a[0] == '%': if b[0] == '%': return ircnick_sort(a[1:], b[1:]) elif b[0] == '@': return 1 else: return -1 elif a[0] == '+': if b[0] == '+': return ircnick_sort(a[1:], b[1:]) elif b[0] in '@%': return 1 else: return -1 else: if a[0] in '{}': if b[0] in special_chars: return cmp(a, b) else: return -1 else: return cmp(a.lower(), b.lower()) def main(): mylist = 'bring all _ball }baby {hall `moo `jump `wall ^wall ]pulp %all [all ^_xall @pall lag +voice %halfop @apple @banana @_cow @__goat +__horse'.split(' ') mylist.sort(ircnick_sort) for i in mylist: print i if __name__ == '__main__': main() # End I hope somebody can help me with this. Thanks in advance. Regards, astigmatik ```
 Re: [Jython-users] Customized list sorting From: - 2007-04-24 05:47:05 ```Sorry for the disturbance. I looked at it again and it was a flaw in my code. It's fixed now =/ On 4/24/07, astigmatik@... wrote: > Using Jython2.2b1, I tried to implement my own sorting. The order of > precedence is: All strings that begin with @ are the "highest" (i.e. > they are top of the list), followed by %, then by +, and then by > "{}[]`\^_|", and only then "a-z" (or alphabetical). > ```