in 2.7 and 3.1 there is special Counter
dict for this purpose.
>>> from collections import Counter
>>> Counter(['apple','red','apple','red','red','pear'])
Counter({'red': 3, 'apple': 2, 'pear': 1})
More Related Contents:
- “pip install unroll”: “python setup.py egg_info” failed with error code 1
- Freezing/Hanging tkinter GUI in waiting for the thread to complete
- Merge pandas dataframes where one value is between two others [duplicate]
- Lists in ConfigParser
- Reference list item by index within Django template?
- Python subprocess.Popen “OSError: [Errno 12] Cannot allocate memory”
- Can Flask have optional URL parameters?
- How to run python scripts using gimpfu from command line?
- How do I get the row count of a Pandas DataFrame?
- Unable to set default python version to python3 in ubuntu
- Selenium Webdriver: How to Download a PDF File with Python?
- Move Character with Vector
- Django formsets: make first required?
- Clustering text documents using scikit-learn kmeans in Python
- Google Groups API add Member
- Python ascii utf unicode
- What python libraries can tell me approximate location and time zone given an IP address?
- In matplotlib, how can I plot a multi-colored line, like a rainbow
- How can I schedule a Task to execute at a specific time using celery?
- how to pass parameters of a function when using timeit.Timer()
- Create new column based on values from other columns / apply a function of multiple columns, row-wise in Pandas
- Access is denied when trying to pip install a package on Windows
- I’m trying to use python in powershell
- Read .csv file from URL into Python 3.x – _csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
- Grouped Bar graph Pandas
- Django widget override template
- About MySQLdb conn.autocommit(True)
- When using cx_Freeze and tkinter I get: “DLL load failed: The specified module could not be found.” (Python 3.5.3)
- Flask-SQLAlchemy Constructor
- How to stop one or multiple for loop(s)