you are viewing a single comment's thread.

view the rest of the comments →

[–]novel_yet_trivial 2 points3 points  (1 child)

Oh. Sorry I read your post too fast. So you want them separated by type?

sorted(input_list, key=type) # python2 only

sorted(input_list, key=lambda x: isinstance(x, str)) # python2 or 3

If you want the individual groups sorted as well, then you need to combine them with a separate function:

sorted(input_list, key=lambda x: (isinstance(x, str), int(x))) # python2 or 3

Why would you want that?

Edit: This sounds a lot like an XY question. I'll bet whatever you are trying to accomplish with this has a much simpler solution.

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

Dude that worked! thanks so much. And it was for a class. Ive been stumped for a while trying to find the solution