gpt4 book ai didi

python - 将行列表拆分为二维数组

转载 作者:行者123 更新时间:2023-12-01 00:03:37 25 4
gpt4 key购买 nike

我在列表中有一组序列,如下所示:

[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]

最佳答案

您可以通过调用 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']]

关于python - 将行列表拆分为二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60134972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com