assisging multiple values to a element in dictionary

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • saif.shakeel@gmail.com

    #1

    assisging multiple values to a element in dictionary

    Hi,
    I have a dictionary which is something like this:
    id_lookup={
    16:'subfunction ',
    26:'dataId',
    34:'parameterId ',
    39:'subfunction ',
    44:'dataPackage Id',
    45:'parameterId ',
    54:'subfunction ',
    59:'dataId',
    165:'subfunctio n',
    169:'subfunctio n',
    170:'dataPackag eId',
    174:'controlPar ameterId'
    }
    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

  • Nick Vatamaniuc

    #2
    Re: assisging multiple values to a element in dictionary

    On May 7, 7:03 am, saif.shak...@gm ail.com wrote:
    Hi,
    I have a dictionary which is something like this:
    id_lookup={
    16:'subfunction ',
    26:'dataId',
    34:'parameterId ',
    39:'subfunction ',
    44:'dataPackage Id',
    45:'parameterId ',
    54:'subfunction ',
    59:'dataId',
    165:'subfunctio n',
    169:'subfunctio n',
    170:'dataPackag eId',
    174:'controlPar ameterId'}
    >
    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]=('dataPackageI D', 'LocallId')

    -Nick V.

    Comment

    • Vyacheslav Maslov

      #3
      Re: assisging multiple values to a element in dictionary

      I have a dictionary which is something like this:
      id_lookup={
      16:'subfunction ',
      26:'dataId',
      34:'parameterId ',
      39:'subfunction ',
      44:'dataPackage Id',
      45:'parameterId ',
      54:'subfunction ',
      59:'dataId',
      165:'subfunctio n',
      169:'subfunctio n',
      170:'dataPackag eId',
      174:'controlPar ameterId'
      }
      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

      Comment

      • Carsten Haese

        #4
        Re: assisging multiple values to a element in dictionary

        On Mon, 2007-05-07 at 04:03 -0700, saif.shakeel@gm ail.com wrote:
        Hi,
        I have a dictionary which is something like this:
        id_lookup={
        16:'subfunction ',
        26:'dataId',
        34:'parameterId ',
        39:'subfunction ',
        44:'dataPackage Id',
        45:'parameterId ',
        54:'subfunction ',
        59:'dataId',
        165:'subfunctio n',
        169:'subfunctio n',
        170:'dataPackag eId',
        174:'controlPar ameterId'
        }
        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



        Comment

        • John Machin

          #5
          Re: assisging multiple values to a element in dictionary

          On May 7, 10:59 pm, Carsten Haese <cars...@uniqsy s.comwrote:
          On Mon, 2007-05-07 at 04:03 -0700, saif.shak...@gm ail.com wrote:
          Hi,
          I have a dictionary which is something like this:
          id_lookup={
          16:'subfunction ',
          26:'dataId',
          34:'parameterId ',
          39:'subfunction ',
          44:'dataPackage Id',
          45:'parameterId ',
          54:'subfunction ',
          59:'dataId',
          165:'subfunctio n',
          169:'subfunctio n',
          170:'dataPackag eId',
          174:'controlPar ameterId'
          }
          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.



          Comment

          • Carsten Haese

            #6
            Re: assisging multiple values to a element in dictionary

            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



            Comment

            • James Stroud

              #7
              Re: assisging multiple values to a element in dictionary

              saif.shakeel@gm ail.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

              Comment

              Working...