keys and values lining up
Michael Haggerty
mhagger at blizzard.harvard.edu
Tue Sep 28 20:08:41 EDT 1999
Nathan Clegg <nathan at islanddata.com> writes:
> d.items() is my backup plan, of course, but I'd rather not. My purpose is
> to insert into a database based on the contents of a dictionary. SQL
> requires a list of keys and a separate list of values:
>
> INSERT INTO table (key1, key2, key3) VALUES (val1, val2, val3)
>
> If I were to use d.items(), I would them have to go back and use the list
> of two-tuples to generate a two-tuple of lists.
There's always
>>> d = {'key1' : 'val1', 'key2' : 'val2', 'key3' : 'val3'}
>>> apply(map, [None] + d.items())
[('key1', 'key2', 'key3'), ('val1', 'val2', 'val3')]
if you have to go the items() route.
Michael
--
Michael Haggerty
mhagger at blizzard.harvard.edu
More information about the Python-list
mailing list