Created
July 22, 2011 13:56
-
-
Save pelletier/1099501 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sort_bug(in_list): | |
""" | |
>>> sort_bug([('bar', '...'), ('bar/baz/bob', '...'), ('bar/baz', '...'), ('foo', '...'), ('foo/bar', '...'), ('a', '...'),]) | |
[('foo/bar', '...'), ('foo', '...'), ('bar/baz/bob', '...'), ('bar/baz', '...'), ('bar', '...'), ('a', '...')] | |
>>> sort_bug([('bar', '...'), ('bar/baz', '...') , ('bar/baz/bob', '...'), ('foo', '...'), ('foo/bar', '...'), ('a', '...'),]) | |
[('foo/bar', '...'), ('foo', '...'), ('bar/baz/bob', '...'), ('bar/baz', '...'), ('bar', '...'), ('a', '...')] | |
""" | |
return sorted(in_list, cmp=lambda a,b: 1 if a[0] <= b[0] else -1) | |
import doctest | |
doctest.testmod() |
see my fork for better comparison (I may be wrong, though)
Sympa, mais en fait, j'ai copié un peu vite mon code a[0] ne test pas
la première lettre, à la base je passe un tuple… My bad
A vrai dire @kizlum nous met tous les 2 d'accord !
https://gist.github.com/1099501
A ces jeunes !
Le vendredi 22 juillet 2011, brunobord
[email protected]
a écrit :
see my fork for better comparison (I may be wrong, though)
https://gist.github.com/1099506
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1099501
##
…---
Twitter : http://twitter.com/nautilebleu/
Skype : nautilebleu
Web : http://nautilebleu.tumblr.com/
Désolé pour la forme criptique : j'ai un faible pour les lambda :)
Nope, à vrai dire je suis assez scié par la simplicité et l'élégance
de ta solution !
Le vendredi 22 juillet 2011, pelletier
[email protected]
a écrit :
Désolé pour la forme criptique : j'ai un faible pour les lambda :)
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1099501
##
…---
Twitter : http://twitter.com/nautilebleu/
Skype : nautilebleu
Web : http://nautilebleu.tumblr.com/
Ah d'ailleurs, si a
et b
sont des tuples, ca change un peu. Cf https://gist.github.com/1099501/0e675e9c708b924079556c313d0ed574e6b7350f
(Edit: note que ca marche a priori pour n'importe quelle profondeur de chemin, et dans n'importe quel ordre)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OK I understand: I get the list from a remote server as ['bar', 'bar/baz', 'bar/baz/bob', 'foo', 'foo/bar'] and not ['bar', 'bar/baz/bob', 'bar/baz', 'foo', 'foo/bar'] so this limitation is not a problem for me.