在列表列表中查找列表的长度时,代码显示的长度不正确,即使我使用的是len()

2024-10-01 05:07:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经创建了一个列表(如下所示)。字符串长度为6个字符,但len返回的是1而不是6,我不明白为什么。 problem code and output

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

Tags: and字符串列表outputlenisascount