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 ? Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ On Thu, 17 May 2018, 19:54 Alexandre Brault, <abra...@mapgears.com> wrote: > > 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? > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list