Dictionary to tuple

Jeff Epler jepler at unpythonic.net
Tue Jun 28 10:57:26 EDT 2005


It looks like you want tuple(d.iteritems())

>>> d = {1: 'one', 2: 'two', 3: 'three'}
>>> tuple(d.iteritems())
((1, 'one'), (2, 'two'), (3, 'three'))

You could also use tuple(d.items()).  The result is essentially the
same.  Only if the dictionary is extremely large does the difference
matter. (or if you're using an older version of Python without the
iteritems method)

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050628/385c00cb/attachment.sig>


More information about the Python-list mailing list