Re: Comparing Dictionaries
- From: Ben Finney <bignose+hates-spam@xxxxxxxxxxxxxxx>
- Date: Fri, 27 Jul 2007 12:55:39 +1000
Kenneth Love <klove@xxxxxxxxxx> writes:
In other words, I consider these two dictionaries to be equivalent:
{ 'dog' : 'bone', 'cat' : 'fever', 'mouse' : 'mickey' }
{ 'mouse' : 'mickey', 'dog' : 'bone', 'cat' : 'fever' }
while these two are not:
{ 'dog' : 'bone', 'cat' : 'fever', 'mouse' : 'mickey' }
{ 'dog' : 'bone', 'cat' : 'fever', 'mouse' : 'michael' }
Any suggestions on how to compare these via some assert statement?
Dictionaries already know how to compare themselves to each other.
>>> {'dog': 'bone', 'cat': 'fever', 'mouse': 'mickey'} == {'mouse': 'mickey', 'dog': 'bone', 'cat': 'fever'}
True
>>> {'dog': 'bone', 'cat': 'fever', 'mouse': 'mickey'} == {'mouse': 'michael', 'dog': 'bone', 'cat': 'fever'}
False
--
\ "Many are stubborn in pursuit of the path they have chosen, few |
`\ in pursuit of the goal." -- Friedrich Nietzsche |
_o__) |
Ben Finney
.
- Follow-Ups:
- Re: Comparing Dictionaries
- From: Kenneth Love
- Re: Comparing Dictionaries
- References:
- Comparing Dictionaries
- From: Kenneth Love
- Comparing Dictionaries
- Prev by Date: Re: instantiate a 'classobj'
- Next by Date: Re: pyparser and recursion problem
- Previous by thread: Comparing Dictionaries
- Next by thread: Re: Comparing Dictionaries
- Index(es):
Relevant Pages
|