Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

for loop to create a set of counters in python

book_title =  ['great', 'expectations','the', 'adventures', 'of', 'sherlock','holmes','the','great','gatsby','hamlet','adventures','of','huckleberry','fin']
word_counter = {}

for word in book_title:
    if word not in word_counter:
        word_counter[word] = 1
    else:
        word_counter[word] += 1

# output
# {'great': 2, 'expectations': 1, 'the': 2, 'adventures': 2, 'of': 2, 'sherlock': 1, 'holmes': 1, 'gatsby': 1, 'hamlet': 1, 'huckleberry': 1, 'fin': 1}
Comment

PREVIOUS NEXT
Code Example
Python :: theta hat symbol python code 
Python :: decorator patter 
Python :: programação orientada a objetos python - Pessoa 
Python :: django router multiple pk 
Python :: networkx draw edge description 
Python :: COMBINE TWO 2-D NUMPY ARRAYS WITH NP.VSTACK 
Python :: dynamically created queryset for PrimaryKeyRelatedField in drf 
Python :: coin flip numpy 
Python :: text files to words generator 
Python :: how to search for element in list python 
Python :: Type conversions in python 
Python :: check for the negative integers and float 
Python :: pep8 E302 
Python :: is complex datatype immutable in python 
Python :: change set item python 
Python :: spark group by alias 
Python :: unique mark boolean django model field 
Python :: check version of various pkgs 
Python :: importing modules in kv lang 
Python :: Summarizing Data and description data in pandas 
Python :: Deleting files which start with a name 
Python :: threshhold crossing on list python 
Python :: get random vowel python 
Python :: Cget subassembly civid3d 
Python :: jupiter output 
Python :: reading a cell from another cell in colab 
Python :: odd or even checker 
Python :: matplotlib show two distinct plots 
Python :: pristine 
Python :: how to serial print line break 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =