小编Bil*_*ann的帖子

元组的平均值

我有一个字典:

{"a":(1, 0.1) , "b":(2, 0.2) , ...}
Run Code Online (Sandbox Code Playgroud)

每个括号都是一个元组,对应于(分数,标准差).如何获取每个元组中第一个整数的平均值?我试过这个:

for word in d:
    (score, std) = d[word]
    d[word]=float(score),float(std)
    if word in string:
        number = len(string)
        v = sum(score)
        return (v) / number
Run Code Online (Sandbox Code Playgroud)

得到此错误:

    v = sum(score)
TypeError: 'int' object is not iterable
Run Code Online (Sandbox Code Playgroud)

python dictionary tuples average list

5
推荐指数
1
解决办法
9135
查看次数

标签 统计

average ×1

dictionary ×1

list ×1

python ×1

tuples ×1