[Python-3000] Builtin iterator type
Mike Klaas
mike.klaas at gmail.com
Tue Nov 14 23:44:07 CET 2006
On 11/14/06, George Sakkis <george.sakkis at gmail.com> wrote:
> On 11/14/06, Mike Klaas <mike.klaas at gmail.com> 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
- 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
More information about the Python-3000
mailing list