What would be the most pythonic way to convert the below list of lists into a single list?
[['MyValue1'], ['MyValue2'], ['MyValue3']]
Desired output"
['MyValue1', 'MyValue2', 'MyValue3']
Thank you in advance!
What would be the most pythonic way to convert the below list of lists into a single list?
[['MyValue1'], ['MyValue2'], ['MyValue3']]
Desired output"
['MyValue1', 'MyValue2', 'MyValue3']
Thank you in advance!
You can use a list comprehension:
lst = [['MyValue1'], ['MyValue2'], ['MyValue3']]
lst = [n[0] for n in lst]
print(lst)
Output:
['MyValue1', 'MyValue2', 'MyValue3']
Assuming every element of my_list is a list of length 1, you can try this:
my_list = [elt[0] for elt in my_list]