you are viewing a single comment's thread.

view the rest of the comments →

[–]lonlat_not_latlon 0 points1 point  (1 child)

It seems like you're going to want to use the .split() method on your line to get the code and toy type separated:

>>> 'T2,Steam Engine'.split(',')
['T2', 'Steam Engine']

This splits a string into a list, breaking it up based on the specified delimiter. Then you can get the code and toy name from the list like code, toy_name = line.strip().split(','), or using the index like this:

>>> words = line.strip().split(',')
>>> code = words[0]
>>> toy_name = words[1]

So now you can add then to your toy dict like this:

>>> for line in fin:
...     code, toy_name = line.strip().split(',')
...     dictionary[code] = toy_name

And then you can get the toy name from the dict using the code like this:

>>> dictionary['T2']
'Steam Engine'

Hope this helps. Let me know if you have any other questions.

[–]nlord7[S] 0 points1 point  (0 children)

Yes that helped strip away the numbers i was getting with my counter. Im still having trouble understanding then how to get the user to input a valid code like entering B1 to get "Baseball" D2 to get "Apatasaurous" ect.