Python Enhancement Proposal for List methods

Schachner, Joseph Joseph.Schachner at Teledyne.com
Mon Oct 22 12:16:40 EDT 2018


I agree with others that I don't see a compelling need to add these to Python, since they are all easy to implement in a few lines.

But what I really want to say is that Python tries hard to be easily readable and easily understood, by any reader.  List.removeall( ) that does not remove all elements, but all occurrences of a value passed to it, does not seem to me to meet that goal.  Even if you implement this as a function I encourage to think of a better name than removeall.  

--- Joseph S.



-----Original Message-----
From: Siva Sukumar Reddy <sukurcf at gmail.com> 
Sent: Sunday, October 21, 2018 8:37 AM
To: python-list at python.org; python-ideas at python.org
Subject: Python Enhancement Proposal for List methods

Hey everyone,

I am really new to Python contribution community want to propose below methods for List object. Forgive me if this is not the format to send an email.

1. *list.replace( item_to_be_replaced, new_item )*: which replaces all the occurrences of an element in the list instead of writing a new list comprehension in place.
2. *list.replace( item_to_be_replaced, new_item, number_of_occurrences )*:
which replaces the occurrences of an element in the list till specific number of occurrences of that element. The number_of_occurrences can defaulted to 0 which will replace all the occurrences in place.
3. *list.removeall( item_to_be_removed )*: which removes all the occurrences of an element in a list in place.

What do you think about these features?
Are they PEP-able? Did anyone tried to implement these features before?
Please let me know.

Thank you,
Sukumar



More information about the Python-list mailing list