On 2020-04-30 1:07 p.m., Ethan Furman wrote:
On 04/30/2020 07:58 AM, Christopher Barker wrote:
On 04/29/2020 10:51 PM, Stephen J. Turnbull wrote:
I think that the issue of searchability and signature are pretty compelling reasons for such a simple feature to be part of the function name.
I would absolutely agree with that if all three function were in the same namespace (like the string methods referred to earlier), but in this case, one is a built in and the others will not be — which makes a huge difference in discoverability.
Imagine someone that uses zip() in code that works for a while, and then discovers a bug triggered by unequal length inputs.
If it’s a flag, they look at the zip docstring, and find the flag, and their problem is solved.
So update the `zip` docstring with a reference to `zip_longest`, `zip_equal`, and `zip_whatever`.
-1 on using a flag.
what about letting `zip` take a `leftover_func` with arguments `partial_results` and `remaining_iterators`, and then provide `zip_longest`, `zip_equal` and `zip_shortest` (default) as functions you can use with it? an iteration of `zip(a, b, c, leftover_func=foo)` would: 1. call next on the first iterator (internal iter(a)) 2. if it fails, call leftover_func with the () tuple as first arg and the (internal iter(b), internal iter(c)) tuple as second arg 3. call next on the second iterator (internal iter(b)) 4. if it fails, call leftover_func with the (result from a,) tuple as the first arg and the (internal iter(a), internal iter(c)) tuple as second arg 5. call next on the third iterator (internal iter(c)) 6. if it fails, call leftover_func with the (result from a, result from b) tuple as the first arg and the (internal iter(a), internal iter(b)) tuple as second arg 7. yield the (result from a, result from b, result from c) tuple the leftover_func should return an iterator that replaces the zip, or None. (zip_shortest would be the no_op function)
-- ~Ethan~ _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/T7OGRP... Code of Conduct: http://python.org/psf/codeofconduct/