Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107656

Re: how to create a dictionary from csv file?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From justin walters <walters.justin01@gmail.com>
Newsgroups comp.lang.python
Subject Re: how to create a dictionary from csv file?
Date Tue, 26 Apr 2016 07:51:28 -0700
Lines 33
Message-ID <mailman.110.1461682290.32212.python-list@python.org> (permalink)
References <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com> <CAO1D73HaJWaD5KPw5+c4grEwVYPmYhJPxQeX_F9Ng4S54xvNrg@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de 4z3VYI69pdbQE012J0R+qwlNc4DOb9DWX6hpa936ILzA==
Return-Path <walters.justin01@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'subject:file': 0.07; 'csv': 0.09; 'subject:create': 0.09; 'python': 0.10; 'python.': 0.11; 'file,': 0.15; '2016': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'task.': 0.16; 'wrote:': 0.16; 'email addr:gmail.com&gt;': 0.18; 'programmer': 0.18; 'keys': 0.22; 'am,': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'pieces': 0.27; 'dictionary': 0.29; 'url:mailman': 0.30; 'anyone': 0.32; 'problem': 0.33; 'url:python': 0.33; 'url:listinfo': 0.34; 'tue,': 0.34; 'file': 0.34; 'received:google.com': 0.35; 'so,': 0.35; 'url:org': 0.36; 'received:209.85': 0.36; 'smaller': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'turn': 0.37; 'received:209': 0.38; 'subject:from': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'called': 0.40; 'show': 0.62; '26,': 0.72; 'hand.': 0.84; 'imagine': 0.96
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to; bh=RPREPnAzcafRoW4IxnLvBxlQgD84ceYXY80ylCJfcg4=; b=CgAdmzpb28p7Sg3nq9xOMwr8EMtxP3bq4k/0awPNdGkDHWElTUZdwuB9SiYrnYS0DW fNFzGezJ6wz8YLBrZRpm825HEHJUawSIFtBvbxfiG5DOlTvUOgbf9X4Dxy6GCqltEYz1 ePyjicSQJ4O9UVPI3Ru7L6qJA9GTfMJvA+CWMJ7LK22f7rFkqjMUWTg2k9JPLqhLGTE/ diMAXBncIMIcH9yGgLX5LLMjRiUx+xaxPH8Wckx6GLcuMGN1g/1N2iYtxErq0QjdBYcF CdzA4yk2VEd+OHuY9o7GIP6I/TuYi/eD3p4PBlKRVJ7yyTMvxtkvqbMqdwszJtwrxHzx FHnw==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to; bh=RPREPnAzcafRoW4IxnLvBxlQgD84ceYXY80ylCJfcg4=; b=Atakkj7DL0X2WMtB1E5QYoqOTOROwOjq7tXqzQIc/H+7gezffD3A+XkhERzLC+/yhn 0x5kRdJ/Jw2odyrwhO0/QmCyF9BWcuwJRZGTMm4VU7Va4WwHQf2F5TrIp9zVXZqNAxdG 1Ha1hX7NhOLSXiRXDGPU1sCGSKLrZ4KU6SZ/dObXcufx+xDB1xj134Ix6QHlp+XIKnaP GX7RC+cqRA7T0I5+IqtJVlUJpubET4sl1ym4yZYcCpMJ+muFHE7NTPdWVQtM9xaH/ilF EBZpbJJeJU17i/+5wYQkLuja1ZwoPXMFGO5n7KI4RZLrYuPEpRavbuexavmwsFf0HxBb iNTQ==
X-Gm-Message-State AOPr4FUF0jBmcL9V1bFBhwzeAZtm6V1g60LDlULOYDmNXpss1RQO0IrwiSFSMIqcyYHBtudYZ+KyzNQhOjomxg==
X-Received by 10.25.15.36 with SMTP id e36mr1516548lfi.148.1461682288423; Tue, 26 Apr 2016 07:51:28 -0700 (PDT)
In-Reply-To <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com>
X-Content-Filtered-By Mailman/MimeDel 2.1.22
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <CAO1D73HaJWaD5KPw5+c4grEwVYPmYhJPxQeX_F9Ng4S54xvNrg@mail.gmail.com>
X-Mailman-Original-References <246c571e-1793-4aa6-9405-19d7a1355598@googlegroups.com>
Xref csiph.com comp.lang.python:107656

Show key headers only | View raw


On Tue, Apr 26, 2016 at 7:18 AM, +dime+ <donald.ng@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?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how to create a dictionary from csv file? "+dime+" <donald.ng@gmail.com> - 2016-04-26 07:18 -0700
  Re: how to create a dictionary from csv file? Peter Otten <__peter__@web.de> - 2016-04-26 16:40 +0200
  Re: how to create a dictionary from csv file? justin walters <walters.justin01@gmail.com> - 2016-04-26 07:51 -0700
  Re: how to create a dictionary from csv file? Tim Chase <python.list@tim.thechases.com> - 2016-04-26 09:36 -0500
    Re: how to create a dictionary from csv file? Hasan Diwan <hasandiwan+usenet@gmail.com> - 2016-04-27 00:36 +0000
  Re: how to create a dictionary from csv file? jfong@ms4.hinet.net - 2016-04-26 19:42 -0700
    Re: how to create a dictionary from csv file? Sibylle Koczian <nulla.epistola@web.de> - 2016-04-27 11:10 +0200
    Re: how to create a dictionary from csv file? Peter Otten <__peter__@web.de> - 2016-04-27 11:31 +0200
    Re: how to create a dictionary from csv file? Sibylle Koczian <nulla.epistola@web.de> - 2016-04-27 17:37 +0200
    Re: how to create a dictionary from csv file? Sibylle Koczian <nulla.epistola@web.de> - 2016-04-27 17:37 +0200

csiph-web