I have a list in Python 2.7 that looks like this.
[[u'ABC'], [u'DEF'], [u'GHI']]
Now, I want to convert it so it should be like this.
['ABC', 'DEF', 'GHI']
How can I do this?
I have a list in Python 2.7 that looks like this.
[[u'ABC'], [u'DEF'], [u'GHI']]
Now, I want to convert it so it should be like this.
['ABC', 'DEF', 'GHI']
How can I do this?
If your list is named arr
you can do arr = [i[0].encode('ascii') for i in arr]
. Note this assumes that each element is a list of only (and at least) one item and that you aren't concerned about there being non-ASCII characters in the string
Welcome to Python. This is just flattening a list
flattened_list = [val[0] for val in [[u'ABC'], [u'DEF'], [u'GHI']]]
print(flattened_list)
By the way please move to Python 3!