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


Groups > comp.lang.python > #66776

Re: The sum of numbers in a line from a file

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <joel.goldstick@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.134
X-Spam-Level *
X-Spam-Evidence '*H*': 0.73; '*S*': 0.00; 'subject:file': 0.07; 'cc:addr:python-list': 0.11; 'columns': 0.16; 'wrote:': 0.18; 'feb': 0.22; 'email addr:gmail.com&gt;': 0.22; 'cc:addr:python.org': 0.22; 'math': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; "i've": 0.25; '&gt;': 0.26; 'this:': 0.26; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'subject:numbers': 0.31; 'file': 0.32; 'url:python': 0.33; 'subject:from': 0.34; 'received:google.com': 0.35; 'add': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'two': 0.37; 'skip:o 20': 0.38; 'skip:& 10': 0.38; 'that,': 0.38; 'url:mail': 0.40; 'skip:\xc2 10': 0.60; 'name': 0.63; 'subject:The': 0.64; 'to:addr:gmail.com': 0.65; 'sample': 0.67; '20,': 0.68; '100': 0.79; '\xc2\xa059': 0.84; 'average': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=7qlCNiU8nRcFSsyqcNzLzcf/jOYK+OfgxwdPfDqZtHU=; b=BNwx428poL5ZjLrs4ZOgEWvXP819mvRGsS4IsqAI0DeB1SUHuIOa5/Vzvk+Al7a4he QgUdujQJU/Gd/x2lFRZZQdVBpE4MHDyRsoljqUR+zfeCetfrzb/69KdFdBtxxMSF8TUp b9H1bVyzMvpgkFCvwOyCXUUSMqLgM6LaLU4Yo4ruroqrfjCdnqQvWRVWQhkRSXVDsbeo 1RcPE9c3gTUNn+SMQHCPUlfDsrtBp6Va0dVeXdpTrxNJdkE2u6PFlNWppSNy5LZx0fsB P1tMjMJiZ2sG+TMvWuutGbwy+d16jQ2moyAmFYlbD+g0SzMeIAD3LCqG1UlUWpr57Rob nnhQ==
MIME-Version 1.0
X-Received by 10.52.183.106 with SMTP id el10mr1277987vdc.73.1392914952128; Thu, 20 Feb 2014 08:49:12 -0800 (PST)
Date Thu, 20 Feb 2014 11:49:12 -0500
Subject Re: The sum of numbers in a line from a file
From Joel Goldstick <joel.goldstick@gmail.com>
To kxjakkk <kjakupak@gmail.com>
Content-Type multipart/alternative; boundary=bcaec547cb97ec8daa04f2d948c4
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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>
Newsgroups comp.lang.python
Message-ID <mailman.7198.1392914960.18130.python-list@python.org> (permalink)
Lines 67
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1392914960 news.xs4all.nl 2933 [2001:888:2000:d::a6]:58148
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:66776

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Feb 20, 2014 11:25 AM, "kxjakkk" <kjakupak@gmail.com> wrote:
>
> Let's say I have a sample file like this:
>
> Name        1           2     3    4     5      6     7    8
> ------------------------------------------------------------------------
> name1    099-66-7871   A-F    Y    100    67    81    59    98
> name2    999-88-7766   A-F    N    99   100    96    91    90
> name3    000-00-0110    AUD        5    100    28    19    76
> name4    398-72-3333    P/F    Y    76    84    49    69    78
> name5    909-37-3689    A-F    Y    97    94    100    61    79
>
> For name1, I want to add together columns 4, 5, 6, and get an average
from that, then do the same for the last two columns. I want to do this for
every name.
>
> All I've got is
> sum([int(s.strip()) for s in open('file').readlines()])
> --

Use split() on each line. Do the math
> https://mail.python.org/mailman/listinfo/python-list

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


Thread

Re: The sum of numbers in a line from a file Joel Goldstick <joel.goldstick@gmail.com> - 2014-02-20 11:49 -0500

csiph-web