Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get method 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:
    word_counter[word] = word_counter.get(word, 0) + 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 :: to the power python markdown 
Python :: how to get device hwid cmd 
Python :: python save console state 
Python :: networkx draw tripartite graph 
Python :: PHP echo multiple lines example Using Heredoc 
Python :: how to use django-filters with viewset 
Python :: Dynamically limiting queryset of related field 
Python :: python why is it important to check the __name__ 
Python :: python write to file while reading 
Python :: python does strftime work with date objects 
Python :: bouon arrondi tkinter 
Python :: Allow Complex Number like "1+2j" to be treated as valid number 
Python :: ex: python 
Python :: cx_freeze include images in specific path 
Python :: python use var in another function 
Python :: ;dslaoeidksamclsoeld,cmskadi934lglllfgl;llgldklkkkkjkklllloooofklllflll;=f]p[ 
Python :: python youtube view bot 
Python :: setting price variable in 3 categories python 
Python :: flask new response style with `make_response` 
Python :: update cell in sheet by column name using pandas 
Python :: numpy substract subsequent elements 
Python :: python check if more than 1 is true 
Python :: copy a 2d list python 
Python :: wxpython mainloop 
Python :: tkinter sin 
Python :: relation api profile does not exist django 
Python :: python move all txt files 
Python :: Walrus operator in list comprehensions [Python 3.8.0] 
Python :: client.futures exchange info() 
Python :: convert from python to curl 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =