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

Karsten Hilbert Karsten.Hilbert at gmx.net
Thu May 17 17:27:44 EDT 2018


> 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 :)

kh



More information about the Python-list mailing list