| View previous topic :: View next topic |
| Author |
Message |
kadamat
Joined: 01 Jun 2006 Posts: 88
|
| Has anyone run into trouble using python dictionaries and having duplicate entries? |
| |
|
|
|
|
Gladis
Joined: 24 May 2006 Posts: 108
|
| kadamat, dicts can only have one value associated with any given key (but that value can be a list, if you so wish) |
| |
|
|
kadamat
Joined: 01 Jun 2006 Posts: 88
|
Yes, that is how it is supposed to work
But how are the keys compared? |
| |
|
|
Gladis
Joined: 24 May 2006 Posts: 108
|
| kadamat, by hash and by ==. |
| |
|
|
kadamat
Joined: 01 Jun 2006 Posts: 88
|
Like of the key is a string, how to I make sure it is checking by value
Hmm, okay then I have a problem here
I read in a file of triples
Compose a key using the first two items and insert it into a dictionary using the third as the value |
| |
|
|
Gladis
Joined: 24 May 2006 Posts: 108
|
| kadamat, are you printing the repr() of the keys? |
| |
|
|
kadamat
Joined: 01 Jun 2006 Posts: 88
|
| No, just the key itself as returned from the k,v iter_items |
| |
|
|
Gladis
Joined: 24 May 2006 Posts: 108
|
| kadamat, are you sure the dupes are actually dupes? Can you give an example of two keys, as printed, that you think are dupes? |
| |
|
|
kadamat
Joined: 01 Jun 2006 Posts: 88
|
N::\en\@eng:aaron:baddeley||Aaron Baddeley]] [[N::\en\@eng:gregory:havret||Gregory Havret]] 2
[[N::\en\@eng:aaron:baddeley||Aaron Baddeley]] [[N::\en\@eng:gregory:havret||Gregory Havret]] 2 |
| |
|
|
Gladis
Joined: 24 May 2006 Posts: 108
|
kadamat, are you assembling a string out of two strings and using that as key? I suggest using a tuple of the two strings, instead.
or, if you are doing that, use repr(key) instead of whatever you're using now to make them into something printable. |
| |
|
|
| Page 1 of 2 |
Goto page 1, 2 Next |
|