Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Libraries

    Counter 1.0.0

    Download button

    No screenshots available
    Downloads: 52  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Thomas Mansencal | More programs
    MIT/X Consortium Lic... / FREE
    September 20th, 2012, 19:45 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    Counter description

    Defines the counter.Counter class

    Counter is a Python module created to define the counter.Counter class similar to multisets or bags in other languages.

    Installation

    pip install Counter

    or:

    easy_install Counter

    or:

    git clone git://github.com/KelSolaar/Counter.git
    python setup.py install


    Usage

    - Tally occurrences of words in a list:

     >>> cnt = Counter()
     >>> for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']:
     ... cnt[word] += 1
     >>> cnt
     Counter({'blue': 3, 'red': 2, 'green': 1})


    - Find the ten most common words in Hamlet:

     >>> import re
     >>> words = re.findall('\w+', open('hamlet.txt').read().lower())
     >>> Counter(hamlet_words).most_common(10)
     [('the', 1143), ('and', 966), ('to', 762), ('of', 669), ('i', 631),
     ('you', 554), ('a', 546), ('my', 514), ('hamlet', 471), ('in', 451)]


    - Multiset examples:

     >>> c = Counter(a=3, b=1)
     >>> d = Counter(a=1, b=2)
     >>> c + d # add two counters together: c[x] + d[x]
     Counter({'a': 4, 'b': 3})
     >>> c - d # subtract (keeping only positive counts)
     Counter({'a': 2})
     >>> c & d # intersection: min(c[x], d[x])
     Counter({'a': 1, 'b': 1})
     >>> c | d # union: max(c[x], d[x])
     Counter({'a': 3, 'b': 2})



    Product's homepage

    Requirements:

    · Python

      


    TAGS:

    counter.Counter class | define counter.Counter | Python library | Python | counter.Counter | class

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM