Skip to content

Instantly share code, notes, and snippets.

View myriasofo's full-sized avatar

Abraham Bae myriasofo

View GitHub Profile
@riceissa
riceissa / inter.py
Created January 10, 2015 20:48
find the intersection of characters given a list of strings
# 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.