-1

I have a list like this:

x = [[(u'reads_2.fq',)], [], [(u'README.txt',)]]

Desired output:

['reads.fq', 'README.txt']
user2545177
  • 81
  • 1
  • 1
  • 5

2 Answers2

0

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']
TerryA
  • 58,805
  • 11
  • 114
  • 143
0

You can try this:

>>> y = []
>>> for a in x:
...     if a:
...         y.append(a[0][0])
...
>>> y
[u'reads_2.fq', u'README.txt']
nazia
  • 75
  • 2
  • 9