On Sat, 21 Nov 2009 21:06:08 -0800, Dennis Lee Bieber wrote:

>       I apparently thought "for ... in dictionary" would return (key,
> value) pairs, but it appears that it only returns the key itself -- and
> a single key can't be unpacked.
> 
>       Misleading error... too many /targets/ to unpack...

No, the error is fine.


>>> for x, y in {1:'a'}:
...     pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unpack non-sequence
>>>
>>> for x, y in {'a':1}:
...     pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: need more than 1 value to unpack
>>>
>>> for x, y in {'parrot':1}:
...     pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: too many values to unpack


Strings are iterable, and so unpack into individual characters.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to