Created
July 28, 2020 21:20
-
-
Save algal/877a699fd4a55985c45e87135aeff284 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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