how to create a dictionary from csv file?

justin walters walters.justin01 at gmail.com
Tue Apr 26 10:51:28 EDT 2016


On Tue, Apr 26, 2016 at 7:18 AM, +dime+ <donald.ng at gmail.com> wrote:

> I am learning python.
>
> if I have a csv file, like this
> banana,4.0
> apple,3.5
> orange,3.0
>
> Can anyone show me how to read the csv file line by line and then create a
> dictionary to contain these keys and values?
>
>
> Regards,
> +dime+
> --
> https://mail.python.org/mailman/listinfo/python-list
>

It's best if you look up how to do this in the docs yourself. An even
better way would be to think about the steps necessary to do this and then
writing them down in pseudo-code. After that you can look up the
functions/tools that will help you accomplish this task. One of the most
important skills a programmer can have is called 'algorithmic thinking'.
That is, essentially, the ability to break a problem down into smaller
pieces in order to eventually solve it.


So, think about this:

What steps do you need to take to turn this csv file into a Python
dictionary object? Imagine that you were going to do this by hand. How
would you do it?



More information about the Python-list mailing list