"Keeping Track of the Produce" - how do I know indices without counting?


Right from the get-go, I don’t know how to do this one and I don’t know where to start. I decided to start by copying/pasting the example code then swapping out the variables that pertain to the code in the exercise.

It kept giving me errors saying “TypeError: string indices must be integers, not dict” which I take to mean I’m supposed to feed it positions in the index and have it print those… but how do I know the index? I mean I can count from left to right to find each specific index, but there has to be a more elegant way. Also: Is the first quotation mark at index [0] or is the “b” from “bananas” at index [0]? Is this not even the correct line of thinking?–am I not even on the right track for completing this exercise?


indexes are for lists:

my_list = ['a', 'b', 'c']
print my_list[0]

to access values in dictionary, you need to use a key:

my_dict = {'a': 'b', 'c': 'd'}
print my_dict['a']

keys are strings, not integers.

prices and stock are dictionaries, as such, you have to index by key, not by index


Thank you! I think I get where to go from here.
Edit: I did, I was able to get it with a minimum of frustration. Thank you!!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.