mapping keys (all occur in the given string) to the position in string
<p>I am trying to get all indexes of the keys in the string and store them in a dict, so that
every index has a list of keys mapping to it.</p>

<p>Example: </p>

<pre><code>string = "loloo and foofoo at the foo bar"
keys = "foo", "loo", "bar", "lo"
</code></pre>

<p>i expect something like</p>

<pre><code>{ 
  0: [lo]
  2: [loo, lo]
 10: [foo]
 13: [foo]
 24: [foo]
 28: [bar]
}
</code></pre>

<p>My current answer loos the following:</p>

<pre><code>def get_index_for_string(string, keys):
    """
    Get all indexes of the keys in the string and store them in a dict, so that
    every index has a list of keys mapping to it.
    """
    key_in_string = dict((key, [m.start() for m in re.finditer(key, string)])
                            for key in keys if key in string)
    index_of_keys = {}
    for key, values in key_in_string.items():
        for value in values:
            if not value in index_of_keys:
                index_of_keys[value] = []
            index_of_keys[value].append(key)
    return index_of_keys
</code></pre>

<p>Any suggestions on how to make this better?</p>
