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


Groups > comp.lang.python > #78704

Re: Issue in printing top 20 dictionary items by dictionary value

Date 2014-10-04 20:40 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: Issue in printing top 20 dictionary items by dictionary value
References <mailman.14596.1412413918.18130.python-list@python.org> <m0oi4p$7ir$1@speranza.aioe.org> <loom.20141004T193031-757@post.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.14605.1412451805.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 2014-10-04 18:36, Shiva wrote:
 > It works :
 > orderedwords = sorted(textstorage.keys(), key=textstorage.get)
 >
 > The method textstorage.get will accept a word and return it's value
 > which in this instance is the count.
 >
 > What I don't understand is:
 >
 >      for w in eachword:
 >          textstorage[w]=textstorage.get(w, 0) + 1
 >
 > How does textstorage.get(w,0)+1 give the count of the word??
 >
What textstorage.get(w, 0) says is: if the word is in the dict, return
its count, else return 0.

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


Thread

Issue in printing top 20 dictionary items by dictionary value Shiva <shivaji_tn@yahoo.com> - 2014-10-04 09:11 +0000
  Re: Issue in printing top 20 dictionary items by dictionary value Alexander Blinne <news@blinne.net> - 2014-10-04 12:28 +0200
    Re: Issue in printing top 20 dictionary items by dictionary value Shiva <shivaji_tn@yahoo.com> - 2014-10-04 17:36 +0000
      Re: Issue in printing top 20 dictionary items by dictionary value Larry Hudson <orgnut@yahoo.com> - 2014-10-04 14:44 -0700
        Re: Issue in printing top 20 dictionary items by dictionary value Shiva <shivaji_tn@yahoo.com> - 2014-10-05 06:58 +0000
    Re: Issue in printing top 20 dictionary items by dictionary value MRAB <python@mrabarnett.plus.com> - 2014-10-04 20:40 +0100
  Re: Issue in printing top 20 dictionary items by dictionary value Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-05 01:11 +0000
    Re: Issue in printing top 20 dictionary items by dictionary value MRAB <python@mrabarnett.plus.com> - 2014-10-05 02:41 +0100

csiph-web