Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Tim Chase Newsgroups: comp.lang.python Subject: Re: how to create a dictionary from csv file? Date: Tue, 26 Apr 2016 09:36:59 -0500 Lines: 19 Message-ID: References: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> <20160426093659.5adc41c6@bigbox.christie.dr> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de yYvvErq3hLmV+H9zZin4yAELNL/pQN7HrayD/LVfzn9g== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:file': 0.07; 'csv': 0.09; 'subject:create': 0.09; 'python.': 0.11; 'file,': 0.15; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'keys': 0.22; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'dictionary': 0.29; 'anyone': 0.32; 'file': 0.34; 'to:addr:python- list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'charset:us-ascii': 0.37; 'data': 0.39; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'show': 0.62; 'more': 0.63; 'received:23': 0.84 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1461688256626:2795576397 X-MC-Ingress-Time: 1461688256625 In-Reply-To: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) X-AuthUser: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <20160426093659.5adc41c6@bigbox.christie.dr> X-Mailman-Original-References: <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> Xref: csiph.com comp.lang.python:107668 On 2016-04-26 07:18, +dime+ 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? import csv with open('data.csv') as f: data = dict(csv.reader(f)) Hard to get much more straight-forward. -tkc