Python Forum
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sort only the odd numbers
#5
(Jul-20-2017, 06:00 PM)nilamo Wrote: Sorting the odd numbers, and then inserting the evens at their original index, would probably be the easiest way, but my guess is that it'd also be the slowest, since you're effectively sorting the list twice.

What would be faster? It's not double sorting, it's sorting once and making one pass. Anything quicker would require keeping the evens in place while sorting once. That would require rewriting the sort algorithm, which I expect would be slower than the optimized sort method.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Sort only the odd numbers - by tomhuang - Jul-20-2017, 05:10 PM
RE: Sort only the odd numbers - by Bass - Jul-20-2017, 05:15 PM
RE: Sort only the odd numbers - by nilamo - Jul-20-2017, 06:00 PM
RE: Sort only the odd numbers - by ichabod801 - Jul-20-2017, 06:02 PM
RE: Sort only the odd numbers - by ichabod801 - Jul-20-2017, 06:07 PM
RE: Sort only the odd numbers - by buran - Jul-20-2017, 08:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Photo a.sort() == b.sort() all the time 3lnyn0 1 1,450 Apr-19-2022, 06:50 PM
Last Post: Gribouillis
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,939 May-09-2019, 12:19 PM
Last Post: Pleiades
  Need Help: Sort of Binary numbers based on 1's present abinashj 5 5,259 Jul-25-2017, 12:23 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020