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!

1

2 Answers 2

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, '-', '-', '-', '-']]
Sign up to request clarification or add additional context in comments.

Comments

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)))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.