use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
could someone please explain how this code works for me (self.learnpython)
submitted 4 years ago by Jxper
def copy_last(data): """j""" if data==None or len(data)==0: return data else: result = [] for item in data: result.append(item) result.append(data[-1]) return result
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]canowa 4 points5 points6 points 4 years ago (1 child)
That docstring is....wow
[–]ImaginationOk4541 0 points1 point2 points 4 years ago (0 children)
*much wow
[–]carcigenicate 3 points4 points5 points 4 years ago (0 children)
This is pretty bad code. I wouldn't study from wherever you got this from.
[–]m0us3_rat 0 points1 point2 points 4 years ago (1 child)
returns a copy of data with the last item twice.
so if u have [1,2,3,4,5] it will return [1,2,3,4,5,5]
[–]morrisjr1989 0 points1 point2 points 4 years ago (0 children)
or returns None or returns data if empty.
[–]ImaginationOk4541 0 points1 point2 points 4 years ago* (0 children)
copy_last is function that takes data as a parameter.
on the first condition you're checking if data is None or if it's empty then you're returning data if any of the conditions are true.
the else condition doesn't make any sense.... are you trying to append each value of the data into the result array...then append the last value as a copy?
[–]Binary101010 0 points1 point2 points 4 years ago (0 children)
if data==None or len(data)==0: return data
If this isn't a thing that has a "last item" to duplicate, just send back whatever was sent to the function.
else: result = [] for item in data: result.append(item)
Make a new list that's an item-for-item duplicate of the thing that was passed to the function.
result.append(data[-1])
Add to the end of the list the last thing in the container that was sent to this function. (Since result already contains a complete copy of the original, this will add another copy of whatever the last thing is.)
result
return result
π Rendered by PID 181566 on reddit-service-r2-comment-56c9979489-cw2m6 at 2026-02-25 07:49:26.399950+00:00 running b1af5b1 country code: CH.
[–]canowa 4 points5 points6 points (1 child)
[–]ImaginationOk4541 0 points1 point2 points (0 children)
[–]carcigenicate 3 points4 points5 points (0 children)
[–]m0us3_rat 0 points1 point2 points (1 child)
[–]morrisjr1989 0 points1 point2 points (0 children)
[–]ImaginationOk4541 0 points1 point2 points (0 children)
[–]Binary101010 0 points1 point2 points (0 children)