keys and values lining up

Nathan Clegg nathan at islanddata.com
Wed Sep 29 14:12:04 EDT 1999


Hmmmm...not sure this worked quite the way you thought it would :)  Output
below.

>>> d = {'key1' : 'val1', 'key2' : 'val2', 'key3' : 'val3'}
>>> keys, values = transpose(d.items())
Traceback (innermost last):
  File "<stdin>", line 1, in ?
ValueError: unpack sequence of wrong size
>>> transpose(d.items())
array([[[k, k, k],
        [v, v, v]],
       [[e, e, e],
        [a, a, a]],
       [[y, y, y],
        [l, l, l]],
       [[1, 2, 3],
        [1, 2, 3]]],'c')
>>> 

It does work when all of the keys and values are numbers, and actually
raises an exception with string keys and numeric values.  Eek!



On 29-Sep-99 Guido van Rossum wrote:
>>     >>> d = {'key1' : 'val1', 'key2' : 'val2', 'key3' : 'val3'}
> Of course, if you have NumPy, there's always
> 
>       keys, values = transpose(d.items())
> 
> which probably beats everything else.
> 
> --Guido van Rossum (home page: http://www.python.org/~guido/)


----------------------------------
Nathan Clegg
 nathan at islanddata.com






More information about the Python-list mailing list