By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

assisging multiple values to a element in dictionary

P: n/a
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

May 7 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On May 7, 7:03 am, saif.shak...@gmail.com wrote:
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.

May 7 '07 #2

P: n/a
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.
--
Vyacheslav Maslov
May 7 '07 #3

P: n/a
On Mon, 2007-05-07 at 04:03 -0700, sa**********@gmail.com wrote:
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,

--
Carsten Haese
http://informixdb.sourceforge.net
May 7 '07 #4

P: n/a
On May 7, 10:59 pm, Carsten Haese <cars...@uniqsys.comwrote:
On Mon, 2007-05-07 at 04:03 -0700, saif.shak...@gmail.com wrote:
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,
Unlikely. "Turning it around" produces one key ('subfunction') with
*FIVE* different values.

May 7 '07 #5

P: n/a
On Mon, 2007-05-07 at 06:06 -0700, John Machin wrote:
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.

--
Carsten Haese
http://informixdb.sourceforge.net
May 7 '07 #6

P: n/a
sa**********@gmail.com wrote:
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
May 7 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.