This is based on previous discussions of possible ways of matching all 
remaining items during destructuring but without iterating of remaining final 
items. This is not exactly a direct replacement for that idea though, and 
skipping iteration of final items might or might not be part of the goal.

In this proposal, the ellipsis (...) can be used in the expression on the left 
side of the equals sign in destructuring anywhere that `*<varname>` can appear 
and has approximately the same meaning. The difference is that when the 
ellipsis is used, the matched items are not stored in variables. This can be 
useful when the matched data might be very large.

..., last_one = <expression>
a, ..., z = <expression>
first_one, ... = <expression>

Additionally, when the ellipsis comes last and the data is being retrieved by 
iterating, stop retrieving items since that might be expensive and we know that 
we will not use them.


Alternative A:

Still iterate over items when the ellipsis comes last (for side effects) but 
introduce a new `final_elipsis` object that is used to stop iteration. The 
negation of `ellipsis` (e.g. `-...`) could return `final_ellipsis` in that case.


Alternative B:

Still iterate over items when the ellipsis comes last (for side effects) and 
don't provide any new means of skipping iteration over final items. The 
programmer can use islice to achieve that.
_______________________________________________
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/QPMFXOOHKQJ6YFM35SJXZMANBQTRZ3FY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to