这是因为
我创建了一个列表列表(如下所示(。字符串有6个字符长,但len返回的是1而不是6,我不知道为什么。问题代码和输出
Motifs = [['AACGTA'],
['CCCGTT'],
['CACCTT'],
['GGATTA'],
['TTCCGG']]
#print(Motifs)
#count = {"A":[],"C":[],"G":[],"T":[]}
#print(count)
stringlenght = Motifs[0]
print(stringlenght)
k = len(stringlenght)
print(k)
#k should be 6 but is printing as 1
n = len('AACGTA')
print(n)
#n which is the same as Motifs[0] prints properly as 6
Motifs[0]
也是一个列表。你可以做k = len(stringlength[0])
,也可以修改Modifs
:
Motifs = ['AACGTA', 'CCCGTT', 'CACCTT', 'GGATTA', 'TTCCGG']
然后它就起作用了。