abs() all() any() ascii() bin() bool() bytearray() bytes() callable() chr() classmethod() compile() complex() delattr() |
dict() dir() divmod() enumerate() eval() exec() filter() float() format() frozenset() getattr() globals() hasattr() hash() |
help() hex() id() input() int() isinstance() issubclass() iter() len() list() locals() map() max() memoryview() |
min() next() object() oct() open() ord() pow() print() property() range() repr() reversed() round() set() |
setattr() slice() sorted() staticmethod() str() sum() super() tuple() type() vars() zip() __import__() |
# Tally occurrences of words in a list
c = Counter()
for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']:
c[word] += 1
print(c)
<Counter({'blue': 3, 'red': 2, 'green': 1})>
import re
words = re.findall(r'\w+',
open('hamlet.txt').read().lower())
Counter(words).most_common(5)
[('the', 1143), ('and', 966), ('to', 762), ('of', 669), ('i', 631)]
https://docs.python.org/3/library/collections.html#collections.Counter
mean() harmonic_mean() median() median_low() median_high() median_grouped() mode() pstdev() pvariance() stdev() variance() |
Arithmetic mean ("average") of data. Harmonic mean of data. Median (middle value) of data. Low median of data. High median of data. Median, or 50th percentile, of grouped data. Mode (most common value) of discrete data. Population standard deviation of data. Population variance of data. Sample standard deviation of data. Sample variance of data. |