What's the cleanest way to compare 2 dictionary?
John Machin
sjmachin at lexicon.net
Thu Aug 10 18:08:23 EDT 2006
John Henry wrote:
> John,
>
> Yes, there are several scenerios.
>
> a) Comparing keys only.
>
> That's been answered (although I haven't gotten it to work under 2.3
> yet)
(1) What's the problem with getting it to work under 2.3?
(2) Why not upgrade?
>
> b) Comparing records.
You haven't got that far yet. The next problem is actually comparing
two *collections* of records, and you need to decide whether for
equality purposes the collections should be treated as an unordered
list, an ordered list, a set, or something else. Then you need to
consider how equality of records is to be defined e.g. case sensitive
or not.
>
> Now it gets more fun - as you pointed out. I was assuming that there
> is no short cut here. If the key exists on both set, and if I wish to
> know if the records are the same, I would have to do record by record
> comparsion. However, since there are only a handful of records per
> key, this wouldn't be so bad. Maybe I just overload the compare
> operator or something.
>
IMHO, "something" would be better than "overload the compare operator".
In any case, you need to DEFINE what you mean by equality of a
collection of records, *then* implement it.
"only a handful":. Naturally 0 and 1 are special, but otherwise the
number of records in the bag shoudn't really be a factor in your
implementation.
HTH,
John
More information about the Python-list
mailing list