why does list's .remove() does not return an object?

Alexandre Brault abrault at mapgears.com
Thu May 17 11:48:22 EDT 2018


On 2018-05-17 11:26 AM, Abdur-Rahmaan Janhangeer wrote:
> I don't understand what this would return? x? You already have x.  Is it
> meant to make a copy? x has been mutated, so I don't understand the benefit
> of making a copy of the 1-less x.  Can you elaborate on the problem you are
> trying to solve?
>
> --Ned.
>
>
> assignment to another var
>
You already have access to the list before removal, the list after
removal and the element to be removed.

Do need a copy of the list before removing x?
>>> old_list = list[:]
>>> list.remove(x)

Do you need the list after removing x?
>>> list.remove(x)  # list is the modified list

Do you need x?
>>> list.remove(x)  # x is x

What else would need to be assigned to another var?



More information about the Python-list mailing list