Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (45.3k points)

I have a dictionary to which I want to append to each drug, a list of numbers. Like this:

append(0), append(1234), append(123), etc.

def make_drug_dictionary(data):

    drug_dictionary={'MORPHINE':[],

                     'OXYCODONE':[],

                     'OXYMORPHONE':[],

                     'METHADONE':[],

                     'BUPRENORPHINE':[],

                     'HYDROMORPHONE':[],

                     'CODEINE':[],

                     'HYDROCODONE':[]}

    prev = None

    for row in data:

        if prev is None or prev==row[11]:

            drug_dictionary.append[row[11][]

    return drug_dictionary

I later want to be able to access the entire set of entries in, for example, 'MORPHINE'.

  1. How do I append a number into the drug_dictionary?
  2. How do I later traverse through each entry?

1 Answer

0 votes
by (16.8k points)

Use append as shown below:

list1 = [1, 2, 3, 4, 5]

list2 = [123, 234, 456]

d = {'a': [], 'b': []}

d['a'].append(list1)

d['a'].append(list2)

print d['a']

Related questions

0 votes
1 answer
0 votes
4 answers
0 votes
4 answers

Browse Categories

...