Skip to content

Instantly share code, notes, and snippets.

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

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 != ' ':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment