Skip to content

Instantly share code, notes, and snippets.

@algal
Created July 28, 2020 21:20
Show Gist options
  • Save algal/877a699fd4a55985c45e87135aeff284 to your computer and use it in GitHub Desktop.
Save algal/877a699fd4a55985c45e87135aeff284 to your computer and use it in GitHub Desktop.
from typing import Dict, List, Tuple
def makeKeyDict(items:List[Tuple]) -> Dict:
"Gives a list of tuples (a,b), returns a dict mapping a to set of b"
d = {}
for (a,b) in items:
d[a] = set([b]).union(d.get(a,set()))
return d
def findKeysWithMultipleValues(keydict) -> List:
ks = []
for (k,v) in keydict.items():
if len(v) > 1:
ks.append(k)
return ks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment