Convert a sequence of sequences to a dictionary and vice-versa
Posted
by louis
on Stack Overflow
See other posts from Stack Overflow
or by louis
Published on 2010-05-06T04:28:19Z
Indexed on
2010/05/06
4:38 UTC
Read the original article
Hit count: 308
One way to manually persist a dictionary to a database is to flatten it into a sequence of sequences and pass the sequence as an argument to cursor.executemany().
The opposite is also useful, i.e. reading rows from a database and turning them into dictionaries for later use.
What's the best way to go from myseq to mydict and from mydict to myseq?
>>> myseq = ((0,1,2,3), (4,5,6,7), (8,9,10,11))
>>> mydict = {0: (1, 2, 3), 8: (9, 10, 11), 4: (5, 6, 7)}
© Stack Overflow or respective owner