0

i tried itertools,map() but i don't knoow what wrong. Ihave this:

[['>Fungi|A0A017STG4.1/69-603 UP-domain-containing protein {ECO:0000313|EMBL:EYE99555.1}', ['-', '-', '-', ... , '-', '-', '-', '-']],['>Fungi|A0A017STG4.1/69-603 UP1-domain-containing protein {ECO:0000313|EMBL:EYE99555.1}', ['-', '-', '-', ... , '-', '-', '-', '-']],['>Fungi|A0A017STG4.1/69-603 UP12-domain-containing protein {ECO:0000313|EMBL:EYE99555.1}', ['-', '-', '-', ... , '-', '-', '-', '-']]]

I want this:

[['>Fungi|A0A017STG4.1/69-603 UP-domain-containing protein {ECO:0000313|EMBL:EYE99555.1}','-', '-', '-', ... , '-', '-', '-', '-'],['>Fungi|A0A017STG4.1/69-603 UP1-domain-containing protein {ECO:0000313|EMBL:EYE99555.1}','-', '-', '-', ... , '-', '-', '-', '-'],['>Fungi|A0A017STG4.1/69-603 UP10-domain-containing protein {ECO:0000313|EMBL:EYE99555.1}','-', '-', '-', ... , '-', '-', '-', '-']]

I tried

for i in x:
    map(i,[])

and this

import itertools
a = [["a","b"], ["c"]]
print list(itertools.chain.from_iterable(a))

pls enlighten me!

Dario
  • 3,905
  • 2
  • 13
  • 27
MTG
  • 191
  • 1
  • 22
  • Possible duplicate of [Flatten (an irregular) list of lists](http://stackoverflow.com/questions/2158395/flatten-an-irregular-list-of-lists) – Jared Goguen Apr 21 '17 at 16:27

2 Answers2

1

There must be better Pythonic solutions, but you can use:

n = []
for x in your_list:
    temp_list = [x[0]]
    [temp_list.append(y) for y in x[1]]
    n.append(temp_list)

print(n)

Outputs:

[['>Fungi|A0A017STG4.1/69-603 UP-domain-containing protein {ECO:0000313|EMBL:EYE99555.1}', '-', '-', '-', Ellipsis, '-', '-', '-', '-'], ['>Fungi|A0A017STG4.1/69-603 UP1-domain-containing protein {ECO:0000313|EMBL:EYE99555.1}', '-', '-', '-', Ellipsis, '-', '-', '-', '-'], ['>Fungi|A0A017STG4.1/69-603 UP12-domain-containing protein {ECO:0000313|EMBL:EYE99555.1}', '-', '-', '-', Ellipsis, '-', '-', '-', '-']]
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
0

simple oneliner can do:

[sum(x, []) for x in yourlist]

note sum(x, []) is rather slow, so for serious list merging use more fun and lighting fast list merging techniques discussed at

join list of lists in python

for example, simple two liner is way faster

import itertools
map(list, (map(itertools.chain.from_iterable, yourlist)))
Community
  • 1
  • 1
Serge
  • 3,387
  • 3
  • 16
  • 34