Alex Gordon
Alex Gordon

Reputation: 60871

python: getting element in a list

def do_work():
  medications_subset2(b,['HYDROCODONE','MORPHINE','OXYCODONE'])

def medications_subset2(b,drugs_needed):
  MORPHINE=['ASTRAMORPH','AVINZA','CONTIN','DURAMORPH','INFUMORPH',
            'KADIAN','MS CONTIN','MSER','MSIR','ORAMORPH',
            'ORAMORPH SR','ROXANOL','ROXANOL 100']
  print drugs_needed[1][0]

how do i print ASTRAMORPH (this is the first element in MORPHINE)

i NEED to make use of drugs_needed, since this is being passed in from do_work

Upvotes: 0

Views: 125

Answers (1)

kennytm
kennytm

Reputation: 523724

Can you define MORPHINE this way?

drugs = {
  'MORPHINE': ['ASTRAMORPH',...],
  'HYDROCODONE': [...],
  ...
}

then you can refer to it by

print ( drugs[drugs_needed[1]][0] )

Upvotes: 4

Related Questions