Re: How to do an 'inner join' with dictionaries

2006-02-27 Thread Michael J. Fromberger
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > Let's say I have two dictionaries: > dict1 is 1:23, 2:76, 4:56 > dict2 is 23:A, 76:B, 56:C > > How do I get a dictionary that is > 1:A, 2:B, 4:C The following should work: j = dict((k, dict2[dict1[k]]) for k in dict1 if dict1[k]

Re: How to do an 'inner join' with dictionaries

2006-02-27 Thread Claudio Grondi
[EMAIL PROTECTED] wrote: > Let's say I have two dictionaries: > dict1 is 1:23, 2:76, 4:56 > dict2 is 23:A, 76:B, 56:C > > How do I get a dictionary that is > 1:A, 2:B, 4:C > Just copy/paste the following source code to a file and run it: sourceCodeToExecute = """ dict1 = { 1:23,2:76,

Re: How to do an 'inner join' with dictionaries

2006-02-27 Thread Antoon Pardon
Op 2006-02-27, [EMAIL PROTECTED] schreef <[EMAIL PROTECTED]>: > Let's say I have two dictionaries: > dict1 is 1:23, 2:76, 4:56 > dict2 is 23:A, 76:B, 56:C > > How do I get a dictionary that is > 1:A, 2:B, 4:C Well how about the straight forward: dict3 = {} for key, value in dict1.iteritems()

Re: How to do an 'inner join' with dictionaries

2006-02-27 Thread Tim Chase
> Let's say I have two dictionaries: > dict1 is 1:23, 2:76, 4:56 > dict2 is 23:A, 76:B, 56:C > > How do I get a dictionary that is > 1:A, 2:B, 4:C >>> d1={1:23,2:76,4:56} >>> d2={23:"a", 76:"b", 56:"c"} >>> result = dict([(d1k,d2[d1v]) for (d1k, d1v) in d1.items()]) >>> result {1: 'a', 2

Re: How to do an 'inner join' with dictionaries

2006-02-27 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > Let's say I have two dictionaries: > dict1 is 1:23, 2:76, 4:56 > dict2 is 23:A, 76:B, 56:C > > How do I get a dictionary that is > 1:A, 2:B, 4:C > >>> dict1 = {1:23, 2:76, 4:56} >>> dict2 = {23:'A', 76:'B', 56:'C'} >>> dict((key, dict2[value]) for key, val

Re: How to do an 'inner join' with dictionaries

2006-02-27 Thread Xavier Morel
[EMAIL PROTECTED] wrote: > Let's say I have two dictionaries: > dict1 is 1:23, 2:76, 4:56 > dict2 is 23:A, 76:B, 56:C > > How do I get a dictionary that is > 1:A, 2:B, 4:C > >>> dict1 = {1:23,2:76,4:56} >>> dict2 = {23:'A',76:'B',56:'C'} >>> dict((k, dict2[v]) for k, v in dict1.items()) {

How to do an 'inner join' with dictionaries

2006-02-27 Thread cyborg4
Let's say I have two dictionaries: dict1 is 1:23, 2:76, 4:56 dict2 is 23:A, 76:B, 56:C How do I get a dictionary that is 1:A, 2:B, 4:C -- http://mail.python.org/mailman/listinfo/python-list