Python Forum
Help with function and sep( , ) value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with function and sep( , ) value
#13
Ok, I see where you are coming from with lines 32-33 now. You basically aren't making a change if the value is already -1, but you use that initial if condition to set up your elif conditions. That works, or you could also just do:
    if reverse_pos != -1 and reverse_pos <= 1:
        new_list = my_list  ##*NOTE* - You have my_list = new_list here, but I think you want new_list = my_list instead.
    elif reverse_pos > list_length -1:
        reverse_pos = list_length -1
Good question about lines 39-40, and I think the answer is no, you don't need them. You've already assigned reverse_pos = number, and that will not be changed if your if and elif conditions are not met.

Also, I don't think you are reading the assignment wrong, but I find the assignment wording a little cryptic myself. The way you've interpreted it makes sense.

(Jun-02-2020, 02:22 PM)drewbty Wrote: With your example for using range, should the second parameter be -1 for my problem? i.e. what makes sense to me is a range starting at the end of the list (list_length -1) and finishing at the start(0), moving in steps of -1?

Yes, the second parameter should be -1. Remember that the stop value is not included in the range, so using -1 as the stop and -1 as the step means you will end at 0.

Note that you don't need to enter your while loop at all if you've already assigned new_list to my_list (since you are just returning the original list), so you'll probably want to add an if condition for that.

To help you figure out the for loop, here is the code you'd use to get new_list to be a copy of my_list with all values in reverse order:
        for i in range((list_length - 1), -1, -1):
                new_list.append(my_list[i])
Reply


Messages In This Thread
Help with function and sep( , ) value - by drewbty - May-31-2020, 09:20 AM
RE: Help with function and sep( , ) value - by GOTO10 - Jun-02-2020, 02:24 PM

Forum Jump:

User Panel Messages

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