Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35105
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <dgcosgrave@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'subject:code': 0.07; 'subject:file': 0.07; 'python': 0.09; 'collections': 0.09; 'subject:same': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; '2.7': 0.13; 'dec': 0.15; 'great!': 0.16; 'subject: \n ': 0.16; 'subject:txt': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'import': 0.21; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; '2.6': 0.27; 'list:': 0.27; 'indentation': 0.29; 'subject:last': 0.30; 'thursday,': 0.30; 'december': 0.32; 'hi,': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'received:209.85': 0.35; 'received:209': 0.37; 'subject:: ': 0.38; 'your': 0.60; 'from:no real name:2**0': 0.60; 'thomas': 0.62; 'subject:...': 0.63; '20,': 0.65 |
| Newsgroups | comp.lang.python |
| Date | Wed, 19 Dec 2012 03:37:25 -0800 (PST) |
| In-Reply-To | <mailman.1040.1355916192.29569.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=122.61.156.48; posting-account=GBJ5twoAAAAUtk007IrGiSpVrG2pLeLK |
| References | <f91585d2-ca8d-4b01-96a0-db817c419858@googlegroups.com> <mailman.1040.1355916192.29569.python-list@python.org> |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| X-Google-IP | 122.61.156.48 |
| MIME-Version | 1.0 |
| Subject | Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file |
| From | dgcosgrave@gmail.com |
| To | comp.lang.python@googlegroups.com |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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 | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Message-ID | <mailman.1043.1355919690.29569.python-list@python.org> (permalink) |
| Lines | 60 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1355919690 news.xs4all.nl 6886 [2001:888:2000:d::a6]:40368 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:35105 |
Show key headers only | View raw
On Thursday, December 20, 2012 12:21:57 AM UTC+13, Thomas Bach wrote: > Hi, > > > > just as a side-note > > > > On Wed, Dec 19, 2012 at 02:45:13AM -0800, : > > > for word in list: > > > if word in dict: > > > count = dict[word] > > > count += 1 > > > dict[word] = count > > > else: > > > dict[word] = 1 > > > > When you got the indentation and names right, you can restate this as > > > > import collections > > counter = collections.Counter(words) > > > > in Python 2.7 or as > > > > import collections > > counter = collections.defaultdict(int) > > for word in words: > > counter[word] += 1 > > > > in Python 2.6 > > > > Regards, > > Thomas. Thanks Thomas for your time... using 2.7 great!
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file dgcosgrave@gmail.com - 2012-12-19 02:45 -0800
Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-12-19 12:55 +0200
Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file dgcosgrave@gmail.com - 2012-12-19 03:28 -0800
Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-19 11:03 +0000
Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file dgcosgrave@gmail.com - 2012-12-19 03:34 -0800
Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file Thomas Bach <thbach@students.uni-mainz.de> - 2012-12-19 12:21 +0100
Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file dgcosgrave@gmail.com - 2012-12-19 03:37 -0800
Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file dgcosgrave@gmail.com - 2012-12-19 03:37 -0800
Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-12-19 13:29 -0500
csiph-web