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
# Fencepost loop using dictionaries. | |
def inters_dict(lst): | |
dct = {ch: True for ch in lst[0]} | |
for s in lst[1:]: | |
dct = {ch: True for ch in s if ch in dct} | |
return dct.keys() | |
# I suspect Pythonistas would find the use of (ch, True) as key-value | |
# pairs to be jarring, so here it is using sets---essentially, the | |
# "True" part is implied by virtue of being in the set. |