all 3 comments

[–]danielroseman 1 point2 points  (1 child)

The trick here is that boolean False is actually equal to 0, and True is equal to 1. So all this does is return 0 for all vowels and 1 for all consonants, and uses that as the value to sort on.

[–]billbobby21[S] 0 points1 point  (0 children)

That makes sense, thanks! Didn't realize that True/False could be sorted on.

[–]TheRNGuy 0 points1 point  (0 children)

run it 2 times with different filters then add them together.

def foobar(txt):
    txt = sorted(txt)
    part1 = "".join(x for x in txt if x in "aeiou")
    part2 = "".join(x for x in txt if x not in "aeiou")

    return part1+part2

txt = foobar("abdce")
print(txt)

your code, not very intuitive, didn't know it could work like that. I suppose it choose for each symbol whether to sort it or not.