Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
dic = {}
for idx, char in enumerate (string):
if char! =' ':
if char not in dic:
dic [char] = [idx]
else:
dic [char].append(idx)
@JimDennis

This comment has been minimized.

Copy link
Owner Author

@JimDennis JimDennis commented Sep 7, 2021

Compare this to:

from collections import defaultdict
d = defaultdict(list)
for i,c in enumerate(s):
    if c != ' ':
        d[c].append(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment