On 21 June 2013 16:56, ALAN GAULD <alan.ga...@btinternet.com> wrote:

> if isinstance(dict(),typein):
>    try: newdict = dict(zip(dl[::2],dl[1::2]))
>    except TypeError:
>     raise ValueError("input lists must be an even length")

Not sure why TypeError and ValueError is used. I would have thought
StopIteration but explain your logic on that as I'm unclear. But the
Exception never tripped, either way. I tried different length
iterables in the zip, but it looks like dict knows tostop before it
trip thems. Only next() does raises the exception. Unless I am
confused ;')

>>> zippy = zip([1,2],[3,4,5,6,7,8,9])
>>> D = dict(zippy)
>>> D
{1: 3, 2: 4} # dict works fine
>>> next(zippy) # exhausting zippy raises StopIteration
Traceback (most recent call last):
  File "<string>", line 301, in runcode
  File "<interactive input>", line 1, in <module>
StopIteration

-- 
Jim
A pride of lions, a gaggle of geese, a pack of wolves, a sewer of bankers.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to