I want to convert this list
myList = [[a], [b], [c]]
Into this list
cleaned_list = [a, b, c]
Is there any solution?
I want to convert this list
myList = [[a], [b], [c]]
Into this list
cleaned_list = [a, b, c]
Is there any solution?
my_list = [['a'], ['b'], ['c', 'd']]
cleaned_list = []
for x in my_list:
for y in x:
cleaned_list.append(y)
print(cleaned_list)
Also there is another solution:
my_list = [['a'], ['b'], ['c', 'd']]
cleaned_list = [y for x in my_list for y in x]
These solutions also work for sublists with many elements.
Maybe a simple list comprehension:
cleaned_list = [i[0] for i in myList]