我尝试了itertools,map(),但是我不知道出了什么问题。我有这样的想法:
[['>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}', ['-', '-', '-', ... , '-', '-', '-', '-']]]我想要这个:
[['>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}','-', '-', '-', ... , '-', '-', '-', '-']]我试过了
for i in x:
map(i,[])还有这个
import itertools
a = [["a","b"], ["c"]]
print list(itertools.chain.from_iterable(a))请指点我!
发布于 2017-04-21 15:49:29
必须有更好的Pythonic解决方案,但您可以使用:
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)产出:
[['>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, '-', '-', '-', '-']]发布于 2017-04-21 15:51:51
简单的单纳可以做到:
[sum(x, []) for x in yourlist]注:和(x,[])相当慢,因此,对于严重的列表合并,请使用更多的乐趣和照明快速列表合并技术。
例如,简单的两条直线要快得多。
import itertools
map(list, (map(itertools.chain.from_iterable, yourlist)))https://stackoverflow.com/questions/43545962
复制相似问题