Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to count the repeatance of every string in a list python

MyList = ["b", "a", "a", "c", "b", "a", "c", 'a']
res = {}

for i in MyList:
    res[i] = MyList.count(i)
    
print(res)

# the output will be a dict
#{'b': 2, 'a': 4, 'c': 2}
Source by tutorial.eyehunts.com #
 
PREVIOUS NEXT
Tagged: #count #repeatance #string #list #python
ADD COMMENT
Topic
Name
8+4 =