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

Ian Kelly ian.g.kelly at gmail.com
Thu May 17 17:34:06 EDT 2018


On Thu, May 17, 2018 at 3:27 PM, Karsten Hilbert
<Karsten.Hilbert at gmx.net> wrote:
>> On 5/17/18 11:57 AM, Abdur-Rahmaan Janhangeer wrote:
>> > x = [0,1]
>> > x.remove(0)
>> > new_list = x
>> >
>> > instead i want in one go
>> >
>> > x = [0,1]
>> > new_list = x.remove(0) # here a way for it to return the modified list by
>> > adding a .return() maybe ?
>>
>> There isn't a way to do that in one line.
>
>    new_list = list(x.remove(0))
>    new_list = x.remove(0)[:]
>
> ?
>
> No one said x can't be modified, only that new_list is
> to contain the modified list after one line of code :)

Did you actually run either of those?



More information about the Python-list mailing list