On Wednesday, May 16, 2018 at 7:42:01 PM UTC-7, Abdur-Rahmaan Janhangeer wrote: > why is x = list.remove(elem) not return the list? > > Abdur-Rahmaan Janhangeer > https://github.com/Abdur-rahmaanJ
1) If you are naming your list "list," you're asking for trouble. Shadowing builtin names is risky. Ten years ago I named a variable "max". Oops. 2) list.remove() operates in-place. Would you expect it to return a copy? Making that copy could potentially use a lot of memory and time. 3) If you do want a copy, construct it from two slices of your original list. Let's say the element you want to remove is at position 6. Then: new_list = old_list[:6] + old_list[7:] 3) -- https://mail.python.org/mailman/listinfo/python-list