Python Forum
sorting a list using unicodes acending order, no loops, no sort(), using recursion
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sorting a list using unicodes acending order, no loops, no sort(), using recursion
#6
(Jun-21-2021, 09:12 AM)bowlofred Wrote: 1) Your function is return()ing information to the caller, but the main program ignores the data that is returned. It just prints the original lst object. If that information isn't necessary, then why are the return statements there? You should be printing the information you got from the function, not the data you called it with. Or you should make sure the function properly sorts the called list (but I don't think it's written to do that).

2) I think what you are trying to do is sort it so the lowest element goes to the front, then sort the rest of the list. So when you recursively call the sort again on line 9, I think you need to start from the beginning (of the now shorter list). So the i needs to be reset to zero for that call.

3) On line 9 sortlist returns a list. On line 3 sortlist returns an element of a list (probably a str the way you've used it). By returning different things, this complicates stuff. I recommend making it always return a list.

4) on line 9 you add two things together. The first is [lst[0]]. This is a list you create with a single element in it. The second is [sortlist(...)]. With step 3 above, this should always be a list. This means you're creating sublists. I think you mean to do something similar to return [lst[0]] + sortlist(...).

explantion:
what i was thinking of doing is, checking if the first unicode is bigger than the next one itll be replaced than i would call the function again but this time itll the check will be with the (i+1) in the list , if "i" reached the list's length itll insert the first character of the list and continue doing this until the length reaches 1 if i has reached 1 it means the last character is the biggest one and itll print it.
obviously somthing is going wrong, i cant understand how to fix it.

im reminding you that im not allowed to use for/while loops only recursion and not supposed to used sort() func. aswell.
to me it seems as if its not checking the last part of the list.
Reply


Messages In This Thread
RE: sorting a list using unicodes acending order, no loops, no sort(), using recursion - by lrn2codee - Jun-21-2021, 09:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to sort a list with duplicates and return their unique indices. Echoroom 3 3,606 Sep-23-2022, 07:53 AM
Last Post: deanhystad
  Count occurences in a string and add to a list using loops Leyo 4 1,758 Mar-11-2022, 03:52 PM
Last Post: Leyo
  Sorting list - Homework assigment ranbarr 1 2,276 May-16-2021, 04:45 PM
Last Post: Yoriz
  Input validation for nested dict and sorting list of tuples ranbarr 3 3,969 May-14-2021, 07:14 AM
Last Post: perfringo
Question Recursion and permutations: print all permutations filling a list of length N SantiagoPB 6 3,406 Apr-09-2021, 12:36 PM
Last Post: GOTO10
  how to sort a list without .sort() function letmecode 3 3,510 Dec-28-2020, 11:21 PM
Last Post: perfringo
  GCF function w recursion and helper function(how do i fix this Recursion Error) hhydration 3 2,590 Oct-05-2020, 07:47 PM
Last Post: deanhystad
  Sorting nested lists in ascending order jszum 2 2,314 May-17-2020, 01:35 PM
Last Post: jefsummers
  Appending to a list in the right order Noobstudent 2 2,348 Dec-07-2019, 10:39 PM
Last Post: Noobstudent
  Question about Sorting a List with Negative and Positive Numbers Than999 2 12,831 Nov-14-2019, 02:44 AM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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