How about something like

def index(self, x):
return next(i for i, a in enumerate(self) if a == x)

Including start and end:

def index(self, x, start=0, end=-1):
return next(i for i, a in tuple(enumerate(self))[start:end] if a == x)

------- Original Message -------
On Friday, March 11th, 2022 at 4:02 PM, Rob Cliffe <rob.cli...@btinternet.com> 
wrote:

> On 11/03/2022 19:30, wfdc wrote:
>
>>> 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?
>
> It was you that said it could be a 1-liner. The burden of proof is on you, if 
> you still want to argue the point.
> Rob Cliffe
_______________________________________________
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/SDI3WIUEWB4CIMA4JU7SBRVRUEFE3TXO/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to