[Python-ideas] proposed methods: list.replace / list.indices
David Kreuter
dkreuter at gmail.com
Mon Dec 31 07:17:32 CET 2012
On Sun, Dec 30, 2012 at 5:58 PM, MRAB <python at mrabarnett.plus.com> wrote:
> On 2012-12-30 16:00, Ned Batchelder wrote:
>>
>> I don't understand the conflict? .replace() from sequence does
>> precisely the same thing as .replace() from bytes if you limit the
>> arguments to single-byte values. It seems perfectly natural to me. I
>> must be missing something.
>>
>> [snip]
> The difference is that for bytes and str it returns the result (they
> are immutable after all), but the suggested addition would mutate the
> list in-place. In order to be consistent it would have to return the
> result instead.
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.
What about .indices though?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20121231/4a78b790/attachment.html>
More information about the Python-ideas
mailing list