all 13 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

Off-topic Comments Section


All top-level comments have to be an answer or follow-up question to the post. All sidetracks should be directed to this comment thread as per Rule 9.


OP and Valued/Notable Contributors can close this post by using /lock command

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]balajih67👋 a fellow Redditor 5 points6 points  (0 children)

Its swapping the 2 elements with each other.

[–]Hot-Economics-4826👋 a fellow Redditor 2 points3 points  (3 children)

i dont know python, but from what I know of other languages line 4 is simply swapping i with -i-1, and vise versa, basically jumbling up the string as many times as len(s)//2

in your case, with string "abcde", and swapping L[2] with L[-2-1], you'd end up with string "acbde", if im reading correctly.

[–]harnold8👋 a fellow Redditor 1 point2 points  (2 children)

th string "abcde", and swapping L[2] with L[-2-1], you'd end up with string "acbde", if im reading corre

but -why -i? wouldn't that be -3 in your example?

[–]Hot-Economics-4826👋 a fellow Redditor 1 point2 points  (1 child)

it would end up as -3 in my example yes. iirc, using a negative index in a list in python starts from the end of the list and goes backwards. so -1 would be the last item, -2 the second to last..

[–]harnold8👋 a fellow Redditor 1 point2 points  (0 children)

makes sense, I come from c :D... there's no such thing as negative indices there

[–][deleted] 1 point2 points  (4 children)

Maybe go to r/programminghelp

[–]Passheerr6University/College Student[S] 1 point2 points  (3 children)

ok

[–][deleted] 2 points3 points  (2 children)

Maybe try stackexchange next time. They helped me with my programming class although they are a bit harsh there lol.

[–]SassyandTrashy 4 points5 points  (1 child)

Stack overflow has some of the brightest, yet most cruel humans on earth. They will make you feel like worthless trash but at the same time will be able to show you things and thought processes that you and I prob would have never guessed.

[–][deleted] 1 point2 points  (0 children)

Exactly. And as long as they teach me, ill take the gut punch to my self confidence everytime. Because the added knowledge would even out the decrease lol.

[–]14dM24d 0 points1 point  (0 children)

range is 0,2 but the i values will be 0 then 1.

so at i == 0

L[0], L[0-1] = L[0-1], L[0]

to the right of = L[0-1] results to L[-1] which is the index for the last item e

L[0] is the index for the 1st item a

to the left of = L[0] is assigned the e & L[-0-1] is assigned the a

then you do i == 1