This is the "translation" of earlier JavaScript post about Counting Same Occurrences . Here, I have Python 2.7.7. The concept The main idea of this function is the same as the JavaScript version (link above - so that I don't have to re-explain it [I'm quite lazy that way] ). In this snippet, I typed a function that generates a dictionary (in JavaScript: object ) output from a list (in JavaScript: array ) input. The output consists of list element : {"index": [array of indexes], "length": array of indexes length} pairs. The "confusing" part was when I tried to initialize the list type for the non-existing dictionary key. The "solution" is using try-except block, with KeyError exception. Let's take a look def occurrence(a): result = {} if isinstance(a, list): # Check input for i, v in enumerate(a): if not isinstance(v, int) or not isinstance(v, str): v = str...