On 11/14/06, Mike Klaas <[EMAIL PROTECTED]> wrote: > On 11/14/06, George Sakkis <[EMAIL PROTECTED]> wrote: > > On 11/14/06, Mike Klaas <[EMAIL PROTECTED]> wrote: > > > > I don't see the problem of importing important language functionality. > > > Most languages since c have required somthing similar. > > > > Most languages since C are not as readable and elegant as Python. I > > think we all agree that list1[5:] + list2 is much better than the > > hypothetical > > list1.getslice(5,None).concatenate(list2) > > or > > from sequenceutils import concatenate, getslice > > concatenate(getslice(list1,5,None), list2) > > > > Unfortunately, people here seem to consider natural the latter when it > > comes to itertools. Oh well, whatever. > > Two differences: > - slicing an iterator is a rare activity; slicing a list is common
Slicing an infinite iterator is *very* common, to which you'll probably reply that infinite iterators are rare. I guess neither of us has numbers to support his claim, so let's leave it at that. > - I often use .extend rather than += when appending iterables to lists > > Finally, your analogy between sequences and iterators is flawed. + > does not work for sequences, but only for concrete types: > > >>> [8] + (9,) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: can only concatenate list (not "tuple") to list > > In python, only concrete types tend to implement syntatic operator > support (another example: sets only support +, -, |, & with other > sets, but their methods accept iterables). > > -Mike > The TypeError is not raised because the arguments are not of a concrete type (all python types are concrete; interfaces or protocols are informal descriptions) but because they're not the *same* type, and I don't object to this. This is not the case in what I propose: in the expression Iter(file('foo')) + Iter(some_string), both operands have the same type, the Iter wrapper that wraps an underlying iterator. George _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com