Python Forum
change normal insertionsort into 2 dimension insertionsort
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
change normal insertionsort into 2 dimension insertionsort
#3
No problem.

Hints:
- iterate over the first dimension, which requires an additional loop on the top
- use the sub element, which is the 2nd dimension, to sort it inline with your algorithm
- key<arr[j][0] is wrong. Remove the [0] and think what this does. Exception: TypeError object is not subscriptable
- you're modifying the original data, which is bad, you could use copy.deepcopy to prevent the change of the original arr
- you should return the sorted 2D-array and not printing them in your function
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: change normal insertionsort into 2 dimension insertionsort - by DeaD_EyE - Mar-27-2020, 11:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to increase speed of access element in 2 dimension array? Diver 6 6,257 Nov-03-2016, 03:42 AM
Last Post: Diver

Forum Jump:

User Panel Messages

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