Le dim. 3 oct. 2021 à 06:01, Stephen J. Turnbull
<stephenjturnb...@gmail.com> a écrit :
>
> Laurent Lyaudet writes:
>  > Hello,
>  >
>  > This is a very simple feature request that does not break anything but
>  > I don't know if you may find it interesting.
>  > It would be nice to have a function or method of list objects that does 
> this :
>  > - First idea :
>  > def enumerate_with_rest(my_list):
>  >     for i, item in enumerate(my_list):
>  >         yield i, item, my_list[:i] + my_list[i + 1:]
>
> First, the name confused me, at least: in many contexts dealing with
> iteration, "rest" means tail.
>
> Second, what's wrong with:
>
>     for i, item in enumerate(my_list):
>         rest = my_list[:i] + my_list[i + 1:]
>         # do stuff with i, item, rest
>
> compared to
>
>     for i, item, rest in enumerate_with_rest(my_list):
>         # do stuff with i, item, rest
>
> You save one line, but you (and everyone who reads your code) needs to
> learn a new function definition, and you need to remember it on every
> invocation.  On the other hand, "explicit is better than implicit"
> (which goes back to my confusion of "rest" with "tail").
>
> Unless you can show both a substantial speedup with a native C
> implementation (which leaves out any Python implementation in a
> different language) and a need for that speed, I'm -1 on defining this
> at all.  It's not one of those cases where defining even a one-line
> function is easy to get semantically wrong.
>

Hello,

Thanks for your feedback.
You do not quote my second email where I also said that
enumerate_with_rest was probably too specific and not worth it.
I would appreciate your feedback on my second email where I stress out
that python is missing a "filter_by_index" construct
and give several propositions.

Best regards,
    Laurent Lyaudet
_______________________________________________
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/L2JCDWBN2QNND426IPEQGD6NP2EEXLJ3/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to