def merge(*sources):
    keyPos = 0
for s in sources:
    s.sort()
while any([(len(s) > 0) for s in sources]):
    topEnum = enumerate([(s[0][keyPos] if len(s) > 0 else None) for s in
        sources])
top = [t for t in topEnum if t[1] is not None]
top.sort(key=lambda a: a[1])
src, key = top[0]
yield sources[src].pop(0)
What is the best way to store set data in Python?