Comparing value in two dictionaries?

2008-11-15 Thread Gilles Ganault
Hello I fill two dictionaries with the same number of keys, and then need to compare the value for each key, eg. #Pour chaque APE, comparaison societe.ape.nombre et verif.ape.nombre import apsw # dic1={} [...] rows=list(cursor.execute(sql)) for id in rows: dic1[id[0]] =

Re: Comparing value in two dictionaries?

2008-11-15 Thread bearophileHUGS
Gilles Ganault: I fill two dictionaries with the same number of keys, and then need to compare the value for each key, eg. Probably using the DBMS capabilities you can find a better solution. Are the keys equal? If you want to do it using dicts, you can iterate on one dict, with iteritems, and

Re: Comparing value in two dictionaries?

2008-11-15 Thread Arnaud Delobelle
Gilles Ganault [EMAIL PROTECTED] writes: Hello I fill two dictionaries with the same number of keys, and then need to compare the value for each key, eg. #Pour chaque APE, comparaison societe.ape.nombre et verif.ape.nombre import apsw # dic1={} [...]

Re: Comparing value in two dictionaries?

2008-11-15 Thread Scott David Daniels
Arnaud Delobelle wrote: Gilles Ganault [EMAIL PROTECTED] writes: Hello I fill two dictionaries with the same number of keys, and then need to compare the value for each key, ... if you know set(dic1) == set(dic2) -- that is that the same keys are used, you could use: Setup: dic1 =

Re: Comparing value in two dictionaries?

2008-11-15 Thread Arnaud Delobelle
Scott David Daniels [EMAIL PROTECTED] writes: Arnaud Delobelle wrote: Gilles Ganault [EMAIL PROTECTED] writes: Hello I fill two dictionaries with the same number of keys, and then need to compare the value for each key, ... if you know set(dic1) == set(dic2) -- that is that the same keys

Re: Comparing value in two dictionaries?

2008-11-15 Thread Arnaud Delobelle
Arnaud Delobelle [EMAIL PROTECTED] writes: Or to obtain a dictionary of differences: dict((k, (v, dic2[v]) for k, v in dic1.iteritems() if dic2[v] != v) ^ Should be k of course! -- Arnaud --