Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

counting the number of items in a list with get in python

counts = {}
names_list = ['John', 'Anne', 'Sam', 'Li', 'Sam', 'John']
for name in names_list:
    counts[name] = counts.get(name,0) +1
print(counts)
Source by www.py4e.com #
 
PREVIOUS NEXT
Tagged: #counting #number #items #list #python
ADD COMMENT
Topic
Name
8+1 =