Giter VIP home page Giter VIP logo

counter's Introduction

Counter

https://secure.travis-ci.org/KelSolaar/Counter.png?branch=master

Introduction

Counter package defines the counter.Counter class similar to bags or multisets in other languages. This package is created from Raymond Hettinger recipe: http://code.activestate.com/recipes/576611/

Installation

To install Counter from the Python Package Index you can issue this command in a shell:

pip install Counter

or this alternative command:

easy_install Counter

Alternatively, if you want to directly install from Github source repository:

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

Usage

For precise usage examples, please refer to the original recipe: http://code.activestate.com/recipes/576611/ and Python documentation: http://docs.python.org/library/collections.html#collections.Counter

  • 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})

About

Counter by Raymond Hettinger – 2009
Copyright© 2009 - Raymond Hettinger
This software is released under terms of MIT license: http://opensource.org/licenses/mit-license.php

counter's People

Contributors

kelsolaar avatar nikolas avatar

Stargazers

 avatar

Watchers

 avatar  avatar

counter's Issues

error: subprocess-exited-with-error

error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [18 lines of output]
Traceback (most recent call last):
File "c:\users\windy\appdata\local\programs\python\python39\lib\site-packages\pip_vendor\pyproject_hooks_in_process_in_process.py", line 353, in
main()
File "c:\users\windy\appdata\local\programs\python\python39\lib\site-packages\pip_vendor\pyproject_hooks_in_process_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "c:\users\windy\appdata\local\programs\python\python39\lib\site-packages\pip_vendor\pyproject_hooks_in_process_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
File "C:\Users\windy\AppData\Local\Temp\pip-build-env-9ca529kp\overlay\Lib\site-packages\setuptools\build_meta.py", line 341, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'])
File "C:\Users\windy\AppData\Local\Temp\pip-build-env-9ca529kp\overlay\Lib\site-packages\setuptools\build_meta.py", line 323, in _get_build_requires
self.run_setup()
File "C:\Users\windy\AppData\Local\Temp\pip-build-env-9ca529kp\overlay\Lib\site-packages\setuptools\build_meta.py", line 487, in run_setup
super(_BuildMetaLegacyBackend,
File "C:\Users\windy\AppData\Local\Temp\pip-build-env-9ca529kp\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in run_setup
exec(code, locals())
File "", line 32, in
File "", line 13, in getLongDescription
UnicodeDecodeError: 'gbk' codec can't decode byte 0x93 in position 2097: illegal multibyte sequence
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.