I have a list like this:
x = [[(u'reads_2.fq',)], [], [(u'README.txt',)]]
Desired output:
['reads.fq', 'README.txt']
I have a list like this:
x = [[(u'reads_2.fq',)], [], [(u'README.txt',)]]
Desired output:
['reads.fq', 'README.txt']
With a list comprehension:
>>> [a for b in x for c in b for a in c]
[u'reads_2.fq', u'README.txt']
Or if you're using Python 2.7 (note that the compiler
module is deprecated, and is not available in python 3):
>>> from compiler.ast import flatten
>>> flatten(x)
[u'reads_2.fq', u'README.txt']
You can try this:
>>> y = []
>>> for a in x:
... if a:
... y.append(a[0][0])
...
>>> y
[u'reads_2.fq', u'README.txt']