> You still haven't shown why a namedtuple is wrong for your use-case.

See Christopher Barker's previous reply to you.

Furthermore, namedtuples have *fieldnames*. Tuples have *indices*. Tuples are 
conceptually more appropriate if we're dealing with what are supposed to be 
numeric indices into some sequential datastructure, rather than a 
dictionary-like one.

> In fact, you haven't shown anything of your use-case, other than that you've 
> written a one-liner and wish that it were a method. What is the larger 
> context in which this is such an incredibly common operation?

1. As already pointed out in the thread, the one-liner is not the most 
efficient way to implement it, nor does it do bounds checking.

2. See the StackOverflow link and the 2 other participants in this thread 
attesting to frequent use of this functionality.

------- Original Message -------

On Friday, March 11th, 2022 at 2:36 PM, Chris Angelico <ros...@gmail.com> wrote:

> On Sat, 12 Mar 2022 at 06:33, wfdc via Python-ideas
>
> python-ideas@python.org wrote:
>
> > > But humans can be confused by "replace" having a totally different API in 
> > > different contexts.
> >
> > I doubt that's the case here.
> >
> > The closest equivalent to tuple's .replace method would be namedtuple's 
> > _.replace method, which also has a different API from string's .replace 
> > method.
> >
> > > I could (I believe) write "count" as an (inefficient) 1-liner, but not 
> > > "index". I suggest it's harder than you think. (Try it!)
> >
> > How much harder? Can you post your candidate?
> >
> > In any case, my point still stands.
> >
> > > "Not every 1-line function needs to be a built-in".
> >
> > Not every 1-line function needs to not be a built-in.
> >
> > > Well, you are 1 user. Have you evidence that there are (many) others?
> >
> > See the StackOverflow link and the 2 other participants in this thread who 
> > attested to frequent use of this functionality.
>
> You still haven't shown why a namedtuple is wrong for your use-case.
>
> In fact, you haven't shown anything of your use-case, other than that
>
> you've written a one-liner and wish that it were a method. What is the
>
> larger context in which this is such an incredibly common operation?
>
> In fact, if it's really such a frequent need, maybe you and/or other
>
> participants can show more than one use-case. That would be helpful in
>
> understanding why tuples need this as a method.
>
> ChrisA
>
> _______________________________________________
>
> Python-ideas mailing list -- python-ideas@python.org
>
> To unsubscribe send an email to python-ideas-le...@python.org
>
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
>
> Message archived at 
> https://mail.python.org/archives/list/python-ideas@python.org/message/H7VCIVQD7EKM426G4PI6TU6JWLFP3POR/
>
> Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/N3CR33COHAUX4OSGYVM7SQUZEJZMUEAO/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to