[Python-Dev] Adding concat function to itertools (original) (raw)
Raymond Hettinger python at rcn.com
Fri Sep 28 23:53:42 CEST 2007
- Previous message: [Python-Dev] Adding concat function to itertools
- Next message: [Python-Dev] Adding concat function to itertools
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Bruce Frederiksen]
I've added a new function to itertools called 'concat'. This function is much like chain, but takes all of the iterables as a single argument.
[Raymond]
Any practical use cases or is this just a theoretical improvement?
For Py2.x, I'm not willing to unnecessarily expand the module. However, for Py3k, I'm open to changing the signature for chain().
[Bruce]
For me, a fraction of chain() uses are of the * variety:
d = defaultdict(list) allvals = chain(*d.values()) return chain(*imap(cache.getitem, keylist)) Interestingly, they seem to all have something to do with dictionary values() that are themselves iterable.
I see. These are instances of a recurring general use case of chain() as a one-level flattener.
Will give consideration to changing the signature of chain() for Py3.0. Besides the concat() variation using a single iterable input, another alternative is the min()/max() style signature where one input is interpreted as iterable and multiple arguments as comprising an input tuple.
Raymond
- Previous message: [Python-Dev] Adding concat function to itertools
- Next message: [Python-Dev] Adding concat function to itertools
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]