[Python-ideas] proposed methods: list.replace / list.indices

Antoine Pitrou solipsis at pitrou.net
Mon Dec 31 12:52:06 CET 2012


On Mon, 31 Dec 2012 07:17:32 +0100
David Kreuter <dkreuter at gmail.com> wrote:
> 
> I don't think that consistency between str and list is desirable. If .index
> for example were consistent in str and list it would look like this:
> 
>     [9, 8, 7, 6, 5].index([8,7]) # = 1
> 
> Also,
>     reversed, sorted (copy)
>     list.reverse, list.sort (in-place)
> From that perspective list.replace working in-place *is* consistent.
> 
> However, I can see that this '.replace' might cause more confusion than
> future code clarity.

Another name could be found if necessary.

> What about .indices though?

I've never needed it myself. The fact that it's O(n) seems to hint that
a list is not the right data structure for the use cases you may be
thinking about :)

Regards

Antoine.





More information about the Python-ideas mailing list