assisging multiple values to a element in dictionary

S

saif.shakeel

Hi,
I have a dictionary which is something like this:
id_lookup={
16:'subfunction',
26:'dataId',
34:'parameterId',
39:'subfunction',
44:'dataPackageId',
45:'parameterId',
54:'subfunction',
59:'dataId',
165:'subfunction',
169:'subfunction',
170:'dataPackageId',
174:'controlParameterId'
}
How do i assign multiple values to the key here.Like i want the
key 170 to take either the name 'dataPackageID' or the name
'LocalId'.I use this in my code,and hence if either comes it should
work .
Can someone help me.
Thanks
 
N

Nick Vatamaniuc

Hi,
I have a dictionary which is something like this:
id_lookup={
16:'subfunction',
26:'dataId',
34:'parameterId',
39:'subfunction',
44:'dataPackageId',
45:'parameterId',
54:'subfunction',
59:'dataId',
165:'subfunction',
169:'subfunction',
170:'dataPackageId',
174:'controlParameterId'}

How do i assign multiple values to the key here.Like i want the
key 170 to take either the name 'dataPackageID' or the name
'LocalId'.I use this in my code,and hence if either comes it should
work .
Can someone help me.
Thanks

id_lookup[170]=('dataPackageID', 'LocallId')

-Nick V.
 
V

Vyacheslav Maslov

I have a dictionary which is something like this:
id_lookup={
16:'subfunction',
26:'dataId',
34:'parameterId',
39:'subfunction',
44:'dataPackageId',
45:'parameterId',
54:'subfunction',
59:'dataId',
165:'subfunction',
169:'subfunction',
170:'dataPackageId',
174:'controlParameterId'
}
How do i assign multiple values to the key here.Like i want the
key 170 to take either the name 'dataPackageID' or the name
'LocalId'.
In general dictionary define strong relation between keys and values,
key should have only one associated value, but in your case value can be
a tuple or list.

Anyway, i think that your question contradict to dictionary concept,
because is impossilbe to assign for some key multiple values.
 
C

Carsten Haese

Hi,
I have a dictionary which is something like this:
id_lookup={
16:'subfunction',
26:'dataId',
34:'parameterId',
39:'subfunction',
44:'dataPackageId',
45:'parameterId',
54:'subfunction',
59:'dataId',
165:'subfunction',
169:'subfunction',
170:'dataPackageId',
174:'controlParameterId'
}
How do i assign multiple values to the key here.Like i want the
key 170 to take either the name 'dataPackageID' or the name
'LocalId'.I use this in my code,and hence if either comes it should
work .

That sounds to me like you're translating names to numbers. If that is
true, you're much better off turning your dictionary around, making the
name the key and the corresponding number the value. That way you'll
have two keys pointing to the same value, which is perfectly legal,
whereas having one key pointing to two values is not really possible.
You could have one key pointing to a list or tuple of two values, but
it's not obvious whether that would solve your problem.

Hope this helps,
 
J

John Machin

That sounds to me like you're translating names to numbers. If that is
true, you're much better off turning your dictionary around, making the
name the key and the corresponding number the value. That way you'll
have two keys pointing to the same value, which is perfectly legal,
whereas having one key pointing to two values is not really possible.
You could have one key pointing to a list or tuple of two values, but
it's not obvious whether that would solve your problem.

Hope this helps,

Unlikely. "Turning it around" produces one key ('subfunction') with
*FIVE* different values.
 
C

Carsten Haese

Unlikely. "Turning it around" produces one key ('subfunction') with
*FIVE* different values.

Whoops! I assumed the OP's problem was reasonably well-formed and didn't
actually check if any of the values were duplicated. I guess the OP will
just have to live with the suggestion of storing tuples or lists, or
explain to us what he's actually trying to achieve.
 
J

James Stroud

Like i want the
key 170 to take either the name 'dataPackageID' or the name
'LocalId'.I use this in my code,and hence if either comes it should
work .

It should work to do what exactly? Cause a perturbation in the orbit of
Mars, or something else entirely?

James
 

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
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top