defining the behavior of zip(it, it)

Alex Martelli aleax at mail.comcast.net
Wed Nov 23 23:54:23 EST 2005


<rurpy at yahoo.com> wrote:
   ...
> cookbook recipies of which there are already several good
> collections, but shorter things like, copy(sequence) is spelled
> "sequence[:]".

No way:

>>> from collections import deque
>>> d=deque([1,2,3])
>>> d[:]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: sequence index must be integer
>>> deque(d)
deque([1, 2, 3])
>>> 

I.e., NOT all sequences implement the unreadable x[:] form.

The way that DOES work with all sequences is typeyouwant(sequence).


Alex



More information about the Python-list mailing list