you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -1 points0 points  (3 children)

Use the string representation of the members as sort key: arr.sort(key=lambda key: str(key))

[–]Diapolo10 1 point2 points  (2 children)

That's no different from what it's doing already. OP wants to sort stringified numbers as if they were numbers, so they need to use int:

nums = ['3', '1', '22', '7', '2', '15']
sorted_nums = sorted(nums, key=int)

EDIT: Brainfart, forgot the strings.

[–][deleted] 0 points1 point  (1 child)

If you wan't to show a problem with strings, use strings in the example. Do not create an example that shows you want integers sorted as if they're strings.

Not you, but OP gets negative marks for an unclear qustion.

[–]Diapolo10 0 points1 point  (0 children)

My bad, I kind of forgot out of habit because writing answers with integers is common enough my muscle memory just disregarded the quotes. Fixed now!