python - multiple key (composite index) search in dict -


i have database table composite index this:

create table table1 ( key1 int, key2 int, value1 int, value2 char(10), primary key(key1 , key2) ) 

i have create dict table (using pyodbc, selection not issue). question is: how define multikey dict , after search data in it.

i achieve sql syntax in dictionary search:

select * table1 key1  = 10 , key2 = 20 

a pseudo code search be:

myvalue = ['a', 'b'] if myvalue in mydict[key1, key2]:     print ('ok') 

but wrong. idea?

a dict must have immutable type key. simplest such structure tupleof 2 database key fields. can use:

mydict[(key1, key2)] 

and should work.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -