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: 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>': 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; '>': 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 To: kxjakkk 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 --bcaec547cb97ec8daa04f2d948c4 Content-Type: text/plain; charset=UTF-8 On Feb 20, 2014 11:25 AM, "kxjakkk" 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 --bcaec547cb97ec8daa04f2d948c4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Feb 20, 2014 11:25 AM, "kxjakkk" <kjakupak@gmail.com> wrote:
>
> Let's say I have a sample file like this:
>
> Name =C2=A0 =C2=A0 =C2=A0 =C2=A01 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 2= =C2=A0 =C2=A0 3 =C2=A0 =C2=A04 =C2=A0 =C2=A0 5 =C2=A0 =C2=A0 =C2=A06 =C2= =A0 =C2=A0 7 =C2=A0 =C2=A08
> ----------------------------------------------------------------------= --
> name1 =C2=A0 =C2=A0099-66-7871 =C2=A0 A-F =C2=A0 =C2=A0Y =C2=A0 =C2=A0= 100 =C2=A0 =C2=A067 =C2=A0 =C2=A081 =C2=A0 =C2=A059 =C2=A0 =C2=A098
> name2 =C2=A0 =C2=A0999-88-7766 =C2=A0 A-F =C2=A0 =C2=A0N =C2=A0 =C2=A0= 99 =C2=A0 100 =C2=A0 =C2=A096 =C2=A0 =C2=A091 =C2=A0 =C2=A090
> name3 =C2=A0 =C2=A0000-00-0110 =C2=A0 =C2=A0AUD =C2=A0 =C2=A0 =C2=A0 = =C2=A05 =C2=A0 =C2=A0100 =C2=A0 =C2=A028 =C2=A0 =C2=A019 =C2=A0 =C2=A076 > name4 =C2=A0 =C2=A0398-72-3333 =C2=A0 =C2=A0P/F =C2=A0 =C2=A0Y =C2=A0 = =C2=A076 =C2=A0 =C2=A084 =C2=A0 =C2=A049 =C2=A0 =C2=A069 =C2=A0 =C2=A078 > name5 =C2=A0 =C2=A0909-37-3689 =C2=A0 =C2=A0A-F =C2=A0 =C2=A0Y =C2=A0 = =C2=A097 =C2=A0 =C2=A094 =C2=A0 =C2=A0100 =C2=A0 =C2=A061 =C2=A0 =C2=A079 >
> 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

--bcaec547cb97ec8daa04f2d948c4--