Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.158 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.69; '*S*': 0.01; 'desirable.': 0.07; 'subject:file': 0.07; 'wrote': 0.14; 'columns': 0.16; 'institution': 0.16; 'skip:d 60': 0.16; 'tends': 0.16; 'travis': 0.16; 'wrote:': 0.18; 'feb': 0.22; 'preferred': 0.22; "i've": 0.25; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'received:172.16': 0.29; 'am,': 0.29; 'room': 0.29; 'lines': 0.31; 'subject:numbers': 0.31; 'yes.': 0.31; 'file': 0.32; 'subject:from': 0.34; 'basic': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'two': 0.37; 'skip:o 20': 0.38; 'message- id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'blank': 0.60; 'dave': 0.60; 'balance': 0.61; 'header:Message-Id:1': 0.63; 'name': 0.63; 'subject:The': 0.64; 'charset:windows-1252': 0.65; 'sample': 0.67; 'between': 0.67; '20,': 0.68; '100': 0.79; '2014,': 0.84; 'angel': 0.91; 'lord': 0.91; 'average': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=HsSnIir+J7bDu/pVSQL8f3nZ+4MMpnV2ZDFkHrL41h0=; b=lM9tJHR1DOywDK0xK+f+EzO5qnwzUtUkDoNjKyjwDnedcENGvutjpTQ0fN6rcWnkbA e0dlJ9vhW7FsIiaKkL4a+DYsz2qyjRvfxtaGw5QGoWdlkYGQu67d3Guemn8jZfljCzck SwuuhbpOAJ+K8V199BLq06/3D/1tEyI4mjeR8pvYYZGxjSo0Ik/aFKY82T+W+lt3pMm2 BYxSdowefDE8fqoY5j6CDW5egkSC6PGQUi9stEpu2QNrMpgRubtks0UAyKH4jtGriKJh fbDfqRBAITk5VI/QiUGUlmCUu6MNGRzwSnwgDBLqTfKlYN33j9GvYFURRswqenz7D3AH ww1g== X-Received: by 10.68.226.70 with SMTP id rq6mr4901657pbc.107.1392935721599; Thu, 20 Feb 2014 14:35:21 -0800 (PST) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.1 \(1827\)) Subject: Re: The sum of numbers in a line from a file From: Travis Griggs In-Reply-To: Date: Thu, 20 Feb 2014 14:35:17 -0800 Content-Transfer-Encoding: quoted-printable References: <882091da-a499-477e-8f50-c5bdde7cdfec@googlegroups.com> To: python-list@python.org X-Mailer: Apple Mail (2.1827) 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: 72 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392935724 news.xs4all.nl 2867 [2001:888:2000:d::a6]:42233 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66784 On Feb 20, 2014, at 8:54 AM, Dave Angel wrote: > kxjakkk Wrote in message: >> Let's say I have a sample file like this: >>=20 >> 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 >>=20 >> 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.=20 >>=20 >> All I've got is >> sum([int(s.strip()) for s in open('file').readlines()]) >>=20 >=20 > Don'ttrytodoitallinoneline.thatwayyouactuallymighthaveaplacetoinse > rtsomeextralogic. >=20 Yes. Clearly the preferred way to do it is with lots of lines with room for expandability. Sorry Dave, couldn=92t resist. Clearly a balance between extremes is = desirable. (Mark, I intentionally put the blank lines in this time ) Travis Griggs "=93Every institution tends to perish by an excess of its own basic = principle.=94 =97 Lord Acton