A simple utility function to merge several lists in a single one, using the functional programming tools:
def merge(*input):
    return reduce(list.__add__, input, list())
Example:
>>> a = [0, 1, 2]
>>> b = [2, 3, 4]
>>> c = [4, 5, 6]
>>> merge(a, b, c)
[0, 1, 2, 2, 3, 4, 4, 5, 6]
The same but removing duplicates:
def merge_uniq(*input):
    return list(reduce(set.union, input, set()))
The same but removing duplicates later:
def merge_uniq(*input):
    return list(set(merge(input)))
Other (easier) ways to achieve the same?


blog comments powered by Disqus