将行列表拆分为2d数组

问题描述 投票:1回答:2

我在一个看起来像这样的列表中有一组序列:

[agghd,gjg,tomt]

如何分割它,这样我的输出如下所示:

[[a,g,g,h,d],[g,j,g],[t,o,m,t]]

我现在已经完成以下代码:

agghd
gjh 
tomt
list2=[]
list2 = [str(sequences.seq).split() for sequences in family]
python arrays list split biopython
2个回答
3
投票

您可以通过在其上调用list()将字符串拆分为字符

list1 = ['agghd', 'gjg', 'tomt']
list2 = [list(string) for string in list1]

# output: [['a', 'g', 'g', 'h', 'd'], ['g', 'j', 'g'], ['t', 'o', 'm', 't']]

0
投票

您可以尝试

[[eval(n) for n in str(sequences.seq).split()] for sequences in family]
© www.soinside.com 2019 - 2024. All rights reserved.