[Python-ideas] os.path.commonprefix: Yes that old chestnut.
Paul Moore
p.f.moore at gmail.com
Tue Mar 24 16:15:45 CET 2015
On 24 March 2015 at 14:44, Andrew Barnert <abarnert at yahoo.com> wrote:
> From my other reply, looking over the functions used in some of the rosettacode examples, it looks like the generic iterable function, when it exists, and the language makes it feasible, often handles an arbitrary number of arguments, not just two. Which makes sense, now that I think about it. So:
>
> def common_prefix(*iterables):
> for first, *rest in zip(*iterables):
> if any(first != part for part in rest):
> return
> yield first
Thanks for the research. This is probably something that could be
included as a recipe in the itertools documentation. (I doubt it would
be viewed as a common enough requirement to be added to the module
itself...) Do you have any objection to me submitting a doc patch with
this code? (It's similar to what I came up with, but a lot cleaner).
Paul
More information about the Python-ideas
mailing list