Link Dictionary

A

anush shetty

Hi,
I have two dictionaries

dict1={'B8': set(['I8', 'H8', 'B2', 'B7', 'F8', 'C9', 'G8', 'B4',
'B5', 'B6', 'C8', 'E8', 'D8', 'B3', 'A9', 'A8', 'C7', 'B9', 'A7',
'B1']), 'B9': set(['I9', 'H9', 'A7', 'F9', 'B3', 'B6', 'G9', 'B4',
'B5', 'C9', 'B7', 'E9', 'B1', 'B2', 'D9', 'A9', 'A8', 'C8', 'B8',
'C7']), 'D1': set(['F1', 'F2', 'F3', 'G1', 'I1', 'D2', 'H1', 'A1',
'D4', 'B1', 'D8', 'D9', 'D6', 'D7', 'C1', 'D5', 'E1', 'D3', 'E3',
'E2'])}

and
dict2=
{'I6': '0', 'H9': '9', 'I2': '0', 'E8': '0', 'H3': '0', 'H7': '0',
'I7': '3', 'I4': '0', 'H5': '0', 'F9': '0', 'G7': '5', 'G6': '9',
'G5': '0', 'E1': '7', 'G3': '2', 'G2': '0', 'G1': '0', 'I1': '0',
'C8': '0', 'I3': '5', 'E5': '0', 'I5': '1', 'C9': '0', 'G9': '0',
'G8': '0', 'A1': '0', 'A3': '3', 'A2': '0', 'A5': '2', 'A4': '0',
'A7': '6', 'A6': '0', 'C3': '1', 'C2': '0', 'C1': '0', 'E6': '0',
'C7': '4', 'C6': '6', 'C5': '0', 'C4': '8', 'I9': '0', 'D8': '0',
'I8': '0', 'E4': '0', 'D9': '0', 'H8': '0', 'F6': '8', 'A9': '0',
'G4': '6', 'A8': '0', 'E7': '0', 'E3': '0', 'F1': '0', 'F2': '0',
'F3': '6', 'F4': '7', 'F5': '0', 'E2': '0', 'F7': '2', 'F8': '0',
'D2': '0', 'H1': '8', 'H6': '3', 'H2': '0', 'H4': '2', 'D3': '8',
'B4': '3', 'B5': '0', 'B6': '5', 'B7': '0', 'E9': '8', 'B1': '9',
'B2': '0', 'B3': '0', 'D6': '2', 'D7': '9', 'D4': '1', 'D5': '0',
'B8': '0', 'B9': '1', 'D1': '0'}

Now I want to create a dict which would have both the keys and values
to be of the corresponding values of dict2.

Something like this:

Eg. The first key in dict1 i.e. B8 as 0 (0 is the value of B8 in
dict2) mapped as set(['0','0','0',...]).

Can anyone help me out with this.
-
Anush
 
G

Gabriel Genellina

En Mon, 11 Jun 2007 17:24:26 -0300, anush shetty
Hi,
I have two dictionaries

dict1={'B8': set(['I8', 'H8', 'B2', 'B7', 'F8', 'C9', 'G8', 'B4',
'B5', 'B6', 'C8', 'E8', 'D8', 'B3', 'A9', 'A8', 'C7', 'B9', 'A7',
'B1']), 'B9': set(['I9', 'H9', 'A7', 'F9', 'B3', 'B6', 'G9', 'B4',
'B5', 'C9', 'B7', 'E9', 'B1', 'B2', 'D9', 'A9', 'A8', 'C8', 'B8',
'C7']), ...

and
dict2=
{'I6': '0', 'H9': '9', 'I2': '0', 'E8': '0', 'H3': '0', 'H7': '0',
'I7': '3', 'I4': '0', 'H5': '0', 'F9': '0', 'G7': '5', 'G6': '9', [...]
'B2': '0', 'B3': '0', 'D6': '2', 'D7': '9', 'D4': '1', 'D5': '0',
'B8': '0', 'B9': '1', 'D1': '0'}

Now I want to create a dict which would have both the keys and values
to be of the corresponding values of dict2.

Something like this:

Eg. The first key in dict1 i.e. B8 as 0 (0 is the value of B8 in
dict2) mapped as set(['0','0','0',...]).

Sets can't have duplicate elements, so set(['0','0','0'])==set(['0'])
And dictionaries can't have duplicate keys either.
What do you want to do exactly? How would your desired structure look like?
 
J

James Stroud

anush said:
Hi,
I have two dictionaries

dict1={'B8': set(['I8', 'H8', 'B2', 'B7', 'F8', 'C9', 'G8', 'B4',
'B5', 'B6', 'C8', 'E8', 'D8', 'B3', 'A9', 'A8', 'C7', 'B9', 'A7',
'B1']), 'B9': set(['I9', 'H9', 'A7', 'F9', 'B3', 'B6', 'G9', 'B4',
'B5', 'C9', 'B7', 'E9', 'B1', 'B2', 'D9', 'A9', 'A8', 'C8', 'B8',
'C7']), 'D1': set(['F1', 'F2', 'F3', 'G1', 'I1', 'D2', 'H1', 'A1',
'D4', 'B1', 'D8', 'D9', 'D6', 'D7', 'C1', 'D5', 'E1', 'D3', 'E3',
'E2'])}

and
dict2=
{'I6': '0', 'H9': '9', 'I2': '0', 'E8': '0', 'H3': '0', 'H7': '0',
'I7': '3', 'I4': '0', 'H5': '0', 'F9': '0', 'G7': '5', 'G6': '9',
'G5': '0', 'E1': '7', 'G3': '2', 'G2': '0', 'G1': '0', 'I1': '0',
'C8': '0', 'I3': '5', 'E5': '0', 'I5': '1', 'C9': '0', 'G9': '0',
'G8': '0', 'A1': '0', 'A3': '3', 'A2': '0', 'A5': '2', 'A4': '0',
'A7': '6', 'A6': '0', 'C3': '1', 'C2': '0', 'C1': '0', 'E6': '0',
'C7': '4', 'C6': '6', 'C5': '0', 'C4': '8', 'I9': '0', 'D8': '0',
'I8': '0', 'E4': '0', 'D9': '0', 'H8': '0', 'F6': '8', 'A9': '0',
'G4': '6', 'A8': '0', 'E7': '0', 'E3': '0', 'F1': '0', 'F2': '0',
'F3': '6', 'F4': '7', 'F5': '0', 'E2': '0', 'F7': '2', 'F8': '0',
'D2': '0', 'H1': '8', 'H6': '3', 'H2': '0', 'H4': '2', 'D3': '8',
'B4': '3', 'B5': '0', 'B6': '5', 'B7': '0', 'E9': '8', 'B1': '9',
'B2': '0', 'B3': '0', 'D6': '2', 'D7': '9', 'D4': '1', 'D5': '0',
'B8': '0', 'B9': '1', 'D1': '0'}

Now I want to create a dict which would have both the keys and values
to be of the corresponding values of dict2.

Something like this:

Eg. The first key in dict1 i.e. B8 as 0 (0 is the value of B8 in
dict2) mapped as set(['0','0','0',...]).

Can anyone help me out with this.
-
Anush

new_dict = {}
for akey, aset in dict1.items():
new_dict[akey] = sum(int(dict2[k]) for k in aset)

James
 
A

anush shetty

anush said:
Hi,
I have two dictionaries
dict1={'B8': set(['I8', 'H8', 'B2', 'B7', 'F8', 'C9', 'G8', 'B4',
'B5', 'B6', 'C8', 'E8', 'D8', 'B3', 'A9', 'A8', 'C7', 'B9', 'A7',
'B1']), 'B9': set(['I9', 'H9', 'A7', 'F9', 'B3', 'B6', 'G9', 'B4',
'B5', 'C9', 'B7', 'E9', 'B1', 'B2', 'D9', 'A9', 'A8', 'C8', 'B8',
'C7']), 'D1': set(['F1', 'F2', 'F3', 'G1', 'I1', 'D2', 'H1', 'A1',
'D4', 'B1', 'D8', 'D9', 'D6', 'D7', 'C1', 'D5', 'E1', 'D3', 'E3',
'E2'])}
and
dict2=
{'I6': '0', 'H9': '9', 'I2': '0', 'E8': '0', 'H3': '0', 'H7': '0',
'I7': '3', 'I4': '0', 'H5': '0', 'F9': '0', 'G7': '5', 'G6': '9',
'G5': '0', 'E1': '7', 'G3': '2', 'G2': '0', 'G1': '0', 'I1': '0',
'C8': '0', 'I3': '5', 'E5': '0', 'I5': '1', 'C9': '0', 'G9': '0',
'G8': '0', 'A1': '0', 'A3': '3', 'A2': '0', 'A5': '2', 'A4': '0',
'A7': '6', 'A6': '0', 'C3': '1', 'C2': '0', 'C1': '0', 'E6': '0',
'C7': '4', 'C6': '6', 'C5': '0', 'C4': '8', 'I9': '0', 'D8': '0',
'I8': '0', 'E4': '0', 'D9': '0', 'H8': '0', 'F6': '8', 'A9': '0',
'G4': '6', 'A8': '0', 'E7': '0', 'E3': '0', 'F1': '0', 'F2': '0',
'F3': '6', 'F4': '7', 'F5': '0', 'E2': '0', 'F7': '2', 'F8': '0',
'D2': '0', 'H1': '8', 'H6': '3', 'H2': '0', 'H4': '2', 'D3': '8',
'B4': '3', 'B5': '0', 'B6': '5', 'B7': '0', 'E9': '8', 'B1': '9',
'B2': '0', 'B3': '0', 'D6': '2', 'D7': '9', 'D4': '1', 'D5': '0',
'B8': '0', 'B9': '1', 'D1': '0'}
Now I want to create a dict which would have both the keys and values
to be of the corresponding values of dict2.
Something like this:
Eg. The first key in dict1 i.e. B8 as 0 (0 is the value of B8 in
dict2) mapped as set(['0','0','0',...]).
Can anyone help me out with this.
-
Anush

new_dict = {}
for akey, aset in dict1.items():
new_dict[akey] = sum(int(dict2[k]) for k in aset)

James


So there is no way I can represent all the duplicates right.

So is there any solution where I could take the values of dictionary
and represent them separately?

-
Anush
 
A

anush shetty

En Mon, 11 Jun 2007 17:24:26 -0300, anush shetty
<[email protected]> escribió:


Hi,
I have two dictionaries
dict1={'B8': set(['I8', 'H8', 'B2', 'B7', 'F8', 'C9', 'G8', 'B4',
'B5', 'B6', 'C8', 'E8', 'D8', 'B3', 'A9', 'A8', 'C7', 'B9', 'A7',
'B1']), 'B9': set(['I9', 'H9', 'A7', 'F9', 'B3', 'B6', 'G9', 'B4',
'B5', 'C9', 'B7', 'E9', 'B1', 'B2', 'D9', 'A9', 'A8', 'C8', 'B8',
'C7']), ...
and
dict2=
{'I6': '0', 'H9': '9', 'I2': '0', 'E8': '0', 'H3': '0', 'H7': '0',
'I7': '3', 'I4': '0', 'H5': '0', 'F9': '0', 'G7': '5', 'G6': '9', [...]
'B2': '0', 'B3': '0', 'D6': '2', 'D7': '9', 'D4': '1', 'D5': '0',
'B8': '0', 'B9': '1', 'D1': '0'}
Now I want to create a dict which would have both the keys and values
to be of the corresponding values of dict2.
Something like this:
Eg. The first key in dict1 i.e. B8 as 0 (0 is the value of B8 in
dict2) mapped as set(['0','0','0',...]).

Sets can't have duplicate elements, so set(['0','0','0'])==set(['0'])
And dictionaries can't have duplicate keys either.
What do you want to do exactly? How would your desired structure look like?

Need it for a verification of the puzzle. It has duplicate values. But
there is any way where i could represent them with duplicates

-
Anush
 
P

Paddy

anush said:
Hi,
I have two dictionaries
dict1={'B8': set(['I8', 'H8', 'B2', 'B7', 'F8', 'C9', 'G8', 'B4',
'B5', 'B6', 'C8', 'E8', 'D8', 'B3', 'A9', 'A8', 'C7', 'B9', 'A7',
'B1']), 'B9': set(['I9', 'H9', 'A7', 'F9', 'B3', 'B6', 'G9', 'B4',
'B5', 'C9', 'B7', 'E9', 'B1', 'B2', 'D9', 'A9', 'A8', 'C8', 'B8',
'C7']), 'D1': set(['F1', 'F2', 'F3', 'G1', 'I1', 'D2', 'H1', 'A1',
'D4', 'B1', 'D8', 'D9', 'D6', 'D7', 'C1', 'D5', 'E1', 'D3', 'E3',
'E2'])}
and
dict2=
{'I6': '0', 'H9': '9', 'I2': '0', 'E8': '0', 'H3': '0', 'H7': '0',
'I7': '3', 'I4': '0', 'H5': '0', 'F9': '0', 'G7': '5', 'G6': '9',
'G5': '0', 'E1': '7', 'G3': '2', 'G2': '0', 'G1': '0', 'I1': '0',
'C8': '0', 'I3': '5', 'E5': '0', 'I5': '1', 'C9': '0', 'G9': '0',
'G8': '0', 'A1': '0', 'A3': '3', 'A2': '0', 'A5': '2', 'A4': '0',
'A7': '6', 'A6': '0', 'C3': '1', 'C2': '0', 'C1': '0', 'E6': '0',
'C7': '4', 'C6': '6', 'C5': '0', 'C4': '8', 'I9': '0', 'D8': '0',
'I8': '0', 'E4': '0', 'D9': '0', 'H8': '0', 'F6': '8', 'A9': '0',
'G4': '6', 'A8': '0', 'E7': '0', 'E3': '0', 'F1': '0', 'F2': '0',
'F3': '6', 'F4': '7', 'F5': '0', 'E2': '0', 'F7': '2', 'F8': '0',
'D2': '0', 'H1': '8', 'H6': '3', 'H2': '0', 'H4': '2', 'D3': '8',
'B4': '3', 'B5': '0', 'B6': '5', 'B7': '0', 'E9': '8', 'B1': '9',
'B2': '0', 'B3': '0', 'D6': '2', 'D7': '9', 'D4': '1', 'D5': '0',
'B8': '0', 'B9': '1', 'D1': '0'}
Now I want to create a dict which would have both the keys and values
to be of the corresponding values of dict2.
Something like this:
Eg. The first key in dict1 i.e. B8 as 0 (0 is the value of B8 in
dict2) mapped as set(['0','0','0',...]).
Can anyone help me out with this.
-
Anush
new_dict = {}
for akey, aset in dict1.items():
new_dict[akey] = sum(int(dict2[k]) for k in aset)

So there is no way I can represent all the duplicates right.

So is there any solution where I could take the values of dictionary
and represent them separately?

-
Anush

I use lists instead of your dict1 but preserve your mapping dict2:

data = [
['B8',
['I8', 'H8', 'B2', 'B7', 'F8',
'C9', 'G8', 'B4', 'B5', 'B6',
'C8', 'E8', 'D8', 'B3', 'A9',
'A8', 'C7', 'B9', 'A7', 'B1']],
['B9',
['I9', 'H9', 'A7', 'F9', 'B3',
'B6', 'G9', 'B4', 'B5', 'C9',
'B7', 'E9', 'B1', 'B2', 'D9',
'A9', 'A8', 'C8', 'B8', 'C7']],
['D1',
['F1', 'F2', 'F3', 'G1', 'I1',
'D2', 'H1', 'A1', 'D4', 'B1',
'D8', 'D9', 'D6', 'D7', 'C1',
'D5', 'E1', 'D3', 'E3', 'E2']]]

dict2= {
'I6': '0', 'H9': '9', 'I2': '0', 'E8': '0', 'H3': '0', 'H7': '0',
'I7': '3', 'I4': '0', 'H5': '0', 'F9': '0', 'G7': '5', 'G6': '9',
'G5': '0', 'E1': '7', 'G3': '2', 'G2': '0', 'G1': '0', 'I1': '0',
'C8': '0', 'I3': '5', 'E5': '0', 'I5': '1', 'C9': '0', 'G9': '0',
'G8': '0', 'A1': '0', 'A3': '3', 'A2': '0', 'A5': '2', 'A4': '0',
'A7': '6', 'A6': '0', 'C3': '1', 'C2': '0', 'C1': '0', 'E6': '0',
'C7': '4', 'C6': '6', 'C5': '0', 'C4': '8', 'I9': '0', 'D8': '0',
'I8': '0', 'E4': '0', 'D9': '0', 'H8': '0', 'F6': '8', 'A9': '0',
'G4': '6', 'A8': '0', 'E7': '0', 'E3': '0', 'F1': '0', 'F2': '0',
'F3': '6', 'F4': '7', 'F5': '0', 'E2': '0', 'F7': '2', 'F8': '0',
'D2': '0', 'H1': '8', 'H6': '3', 'H2': '0', 'H4': '2', 'D3': '8',
'B4': '3', 'B5': '0', 'B6': '5', 'B7': '0', 'E9': '8', 'B1': '9',
'B2': '0', 'B3': '0', 'D6': '2', 'D7': '9', 'D4': '1', 'D5': '0',
'B8': '0', 'B9': '1', 'D1': '0'}

dout = [[dict2,[dict2[k] for k in j]]
for i,j in data]
print dout

- Paddy.
 
P

Paddy

dout = [[dict2,[dict2[k] for k in j]]
for i,j in data]
print dout

- Paddy.


Working from your original dict1:

dout = [[dict2, [dict2[k] for k in setvalue]]
for i,setvalue in dict1.iteritems()]

- Paddy
 
J

James Stroud

anush said:
anush said:
Hi,
I have two dictionaries
dict1={'B8': set(['I8', 'H8', 'B2', 'B7', 'F8', 'C9', 'G8', 'B4',
'B5', 'B6', 'C8', 'E8', 'D8', 'B3', 'A9', 'A8', 'C7', 'B9', 'A7',
'B1']), 'B9': set(['I9', 'H9', 'A7', 'F9', 'B3', 'B6', 'G9', 'B4',
'B5', 'C9', 'B7', 'E9', 'B1', 'B2', 'D9', 'A9', 'A8', 'C8', 'B8',
'C7']), 'D1': set(['F1', 'F2', 'F3', 'G1', 'I1', 'D2', 'H1', 'A1',
'D4', 'B1', 'D8', 'D9', 'D6', 'D7', 'C1', 'D5', 'E1', 'D3', 'E3',
'E2'])}
and
dict2=
{'I6': '0', 'H9': '9', 'I2': '0', 'E8': '0', 'H3': '0', 'H7': '0',
'I7': '3', 'I4': '0', 'H5': '0', 'F9': '0', 'G7': '5', 'G6': '9',
'G5': '0', 'E1': '7', 'G3': '2', 'G2': '0', 'G1': '0', 'I1': '0',
'C8': '0', 'I3': '5', 'E5': '0', 'I5': '1', 'C9': '0', 'G9': '0',
'G8': '0', 'A1': '0', 'A3': '3', 'A2': '0', 'A5': '2', 'A4': '0',
'A7': '6', 'A6': '0', 'C3': '1', 'C2': '0', 'C1': '0', 'E6': '0',
'C7': '4', 'C6': '6', 'C5': '0', 'C4': '8', 'I9': '0', 'D8': '0',
'I8': '0', 'E4': '0', 'D9': '0', 'H8': '0', 'F6': '8', 'A9': '0',
'G4': '6', 'A8': '0', 'E7': '0', 'E3': '0', 'F1': '0', 'F2': '0',
'F3': '6', 'F4': '7', 'F5': '0', 'E2': '0', 'F7': '2', 'F8': '0',
'D2': '0', 'H1': '8', 'H6': '3', 'H2': '0', 'H4': '2', 'D3': '8',
'B4': '3', 'B5': '0', 'B6': '5', 'B7': '0', 'E9': '8', 'B1': '9',
'B2': '0', 'B3': '0', 'D6': '2', 'D7': '9', 'D4': '1', 'D5': '0',
'B8': '0', 'B9': '1', 'D1': '0'}
Now I want to create a dict which would have both the keys and values
to be of the corresponding values of dict2.
Something like this:
Eg. The first key in dict1 i.e. B8 as 0 (0 is the value of B8 in
dict2) mapped as set(['0','0','0',...]).
Can anyone help me out with this.
-
Anush

new_dict = {}
for akey, aset in dict1.items():
new_dict[akey] = sum(int(dict2[k]) for k in aset)

James



So there is no way I can represent all the duplicates right.

So is there any solution where I could take the values of dictionary
and represent them separately?

-
Anush

Just leave off the sum and turn the generator into a list comprehension:

new_dict = {}
for akey, aset in dict1.items():
new_dict[akey] = [dict2[k] for k in aset]

James
 
A

anush shetty

Working from your original dict1:

dout = [[dict2, [dict2[k] for k in setvalue]]
for i,setvalue in dict1.iteritems()]

- Paddy



I dont think this works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top