A slightly more efficient way to do this:
>>> first = [1, 2, 3, 4] >>> second = [3, 2, 5, 6, 7] # New way >>> list(set(first + second)) [1, 2, 3, 4, 5, 6, 7] #1000000 loops, best of 3: 1.42 ยตs per loop # Old way >>> list(set(first) | set(second)) [1, 2, 3, 4, 5, 6, 7] #1000000 loops, best of 3: 1.83 ยตs per loop
The new method is more efficient since it has only one set () instead of 2.
benjaryu Jan 13 '16 at 9:16 2016-01-13 09:16
source share