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.

_______________________________________________
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/NPGODVCFSIDAAVOR6XSCZQQK6IFDULP2/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to