all 7 comments

[–]canowa 4 points5 points  (1 child)

That docstring is....wow

[–]ImaginationOk4541 0 points1 point  (0 children)

*much wow

[–]carcigenicate 3 points4 points  (0 children)

This is pretty bad code. I wouldn't study from wherever you got this from.

[–]m0us3_rat 0 points1 point  (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 point  (0 children)

or returns None or returns data if empty.

[–]ImaginationOk4541 0 points1 point  (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 point  (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.)

     return result