Jack Diederich wrote: > On Thu, Sep 01, 2005 at 07:58:40PM +0200, Paolino wrote: > >>Working on a tree library I've found myself writing >>itertools.chain(*[child.method() for child in self]). >>Well this happened after I tried instinctively >>itertools.chain(child.method() for child in self). >> >>Is there a reason for this signature ? > > > This is more suited to comp.lang.python > Why ? I'm not asking for help ,I'm asking why itertools library is implemented like that and if it is possible to clean it.
> Consider the below examples (and remember that strings are iterable) > > >>>>import itertools as it >>>>list(it.chain('ABC', 'XYZ')) > > ['A', 'B', 'C', 'X', 'Y', 'Z'] > >>>>list(it.chain(['ABC', 'XYZ'])) > > ['ABC', 'XYZ'] > >>>>list(it.chain(['ABC'], ['XYZ'])) > > ['ABC', 'XYZ'] > What if I want to chain an infinite list of iterables? Shouldn't itertools.chain be built to handle that? I don't think it is a problem to accept only the second case you paste and produce TypeError on the others. Hope this explains and to get other reasons. Regards Paolino > > Hope that helps, > > -jackdied > _______________________________________________ > Python-Dev mailing list > Python-Dev@python.org > http://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > http://mail.python.org/mailman/options/python-dev/paolo_veronelli%40libero.it > _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com