新来的。请看一下我的docstring,看看我想做什么:
def count(data):
""" (list of list of str) -> list of int
Return the numbers of occurrences of strings that end in digits 0, 1, or 2
for each string.
>>> data = [['N', 'OW1'], ['Y', 'EH1', 'S'], ['AW1', 'OW1']]
>>> count(data)
[1, 1, 2]
"""
num_list = []
num = 0
for sublist in phonemes:
for item in sublist:
if item[-1].isdigit():
num += 1
num_list.append(num)
return num_list
我不知道如何为每个data
sublist
创建一个数字。这是正确的方法吗?任何帮助都会很好。你知道吗
通过你的理解。你知道吗
我认为您的想法是正确的,但在完成子列表后,您不会将
num
重置为0。现在要做的是计算所有子列表中的数字0,1,2的总数。您需要的是每个子列表的计数。你知道吗在遍历整个子列表之后,还必须附加
num
。所以你需要把它从内部for循环体中去掉。你知道吗修订日期:
试试这个。你知道吗
相关问题 更多 >
编程相关推荐