tags:

views:

54

answers:

2
  generic_drugs_mapping={'MORPHINE':[86],
                        'OXYCODONE':[87],
                        'OXYMORPHONE':[99],
                        'METHADONE':[82],
                        'BUPRENORPHINE':[28],
                        'HYDROMORPHONE':[54],
                        'CODEINE':[37],
                        'HYDROCODONE':[55]}

how do i return 86 ?

this does not seem to work:

print generic_drugs_mapping['MORPHINE'[0]]
+5  A: 

You have a bracket in the wrong place:

print generic_drugs_mapping['MORPHINE'][0]

Your code is indexing the string 'MORPHINE', so it's equivalent to

print generic_drugs_mapping['M']

Since 'M' is not a key in your dictionary, you won't get the results you expect.

Greg Hewgill
Not sure what you meant with the second part but it is wrong 'M' is not a key in the dict that he setup.
Amoss
Ah I see what you mean. I misread what you have written.
Amoss
@Greg: and if `'M'` was a key in his dictionary, he still wouldn't get the expected results, unless 'M' mapped to `86` ;-)
John Machin
+2  A: 

The list is the value stored under the key. The part that gets the value out is generic_drugs_mapping['MORPHINE'] so this has the value [86]. Try moving the index outside like this :

generic_drugs_mapping['MORPHINE'][0]
Amoss