#字典的一键多值
print ' Scheme A list is allowed to repeat as a value of Dict '
d1={}
Key=1
value=2
D1.setdefault (key,[]). Append (value)
value=2
D1.setdefault (key,[]). Append (value)
Print D1
#获取值
print ' Scheme one get value '
Print List (D1[key])
print ' scheme deletes a value, leaving an empty list '
D1[key].remove (value)
D1[key].remove (value)
Print D1
print ' Scenario One checks if there is a value '
Print D1.get (key,[])
print ' scenario two using a sub-dictionary as a value value for Dict does not allow duplicates '
d1={}
Key=1
keyin=2
value=11
D1.setdefault (key,{}) [Keyin]=value
keyin=2
Value=22
D1.setdefault (key,{}) [Keyin]=value
Keyin=3
Value=33
D1.setdefault (key,{}) [Keyin]=value
Print D1
print ' Scenario two get value '
Print List (D1[key])
print ' Scenario Two delete value, leaving an empty list '
Del D1[key][keyin]
keyin=2
Del D1[key][keyin]
Print D1
print ' Scenario Two check if there is a value '
Print D1.get (key, ())
print ' scenario three using Set as Dict value value does not allow duplicates '
d1={}
Key=1
value=2
D1.setdefault (Key,set ()). Add (Value)
value=2
D1.setdefault (Key,set ()). Add (Value)
Value=3
D1.setdefault (Key,set ()). Add (Value)
Print D1
print ' Scheme three get value '
Print List (D1[key])
print ' Scenario Three delete value, leaving an empty list '
D1[key].remove (value)
value=2
D1[key].remove (value)
Print D1
print ' Scheme Three check if there is a value '
Print D1.get (key, ())
Scenario A list is allowed to repeat as a value value of Dict
{1: [2, 2]}
Get value
[2, 2]
Delete value, leaving an empty list
{1: []}
Check if there is a value
[]
Scenario two value values that use a sub-dictionary as dict do not allow duplicates
{1: {2:22, 3:33}}
Get value
[2, 3]
Delete value, leaving an empty list
{1: {}}
Check if there is a value
{}
Scenario three value values that use Set as dict do not allow duplicates
{1:set ([2, 3])}
Get value
[2, 3]
Delete value, leaving an empty list
{1:set ([])}
Check if there is a value
Set ([])
Python Dictionary One-click Multi-valued, that is, one key corresponds to multiple values