I have got 20-25+ lists in python and I want to check all the items within the list and put single items into a new list.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | I have got 20-25+ lists in python and I want to check all the items within the list and put single items into a new list.
['a','b', 'c', 'd', 'e']
['a', 'e', 'c', 'x']
['f', 'g', 'k', 'y']
['a', 'z', 't']**strong text**
.
.
.
.
.
.
.
.
#single elements from number of list into one
new = ['a', 'b','c', 'd', 'e', 'f', 'g'........]
|
You could first convert your lists into a set. In python, a set is a dictionary that contains only keys and no values. Since keys are unique, duplicate entries are eliminated automatically. Then, convert the set back into a list and print. You can achieve this with a nice one-liner:
print list(set().union(a, b, c))