How can I code to read the first line from a file and put it as a key value of a dictionary and keep reading next values in a iterative manner and put them as the values to the particular key they fall into in the file.
Like example:
Item Quality Cost Place
Ball 1 $12 TX
Umbrella 5 $35 NY
sweater 89 $100 LA
So here, the representation is my file. When I read, I want the dictionary to be created as in the things in bold go as keys and when i keep reading lines below that, I would have them going as multiple values in the respective keys.
thanks
You can’t have “multiple values” for a given key, but you can of course have one value per key that’s a list.
For example (Python 2.6 or better — simply because I use the
nextfunction for generality rather than methods such asreadline, but you can of course tweak that!):