Scripting >> Python >> Solving common problems using python

 

S/N Problem Example
1 Count frequency of items in a list >>> def count_letters(text):
...   result={}
...   for letter in text:
...      if letter not in result:
...         result[letter] = 0
...      result[letter] += 1
...   return result
...
>>> count_letters('tenant')
{'a': 1, 'e': 1, 't': 2, 'n': 2}