lst = ['10010001','01101001']
我需要计算每个元素中出现数字'1'的次数
答案 0 :(得分:0)
for element in lst:
print element.count("1")
答案 1 :(得分:0)
>>> lst = ['10010001','01101001']
>>> [l.count('1') for l in lst]
[3, 4]
答案 2 :(得分:-1)
from collections import Counter
num_of_1s = [Counter(item)['1'] for item in lst]