首页 > 其他 > 详细

练习1

时间:2020-01-03 21:49:23      阅读:112      评论:0      收藏:0      [点我收藏+]
‘‘‘有一个列表[3,4,1,2,5,6,6,5,4,3,3]请写出一个函数,找出该列表中没有重复的数的总和‘‘‘
def func(l):
    res = []
    sum_s = 0
    for i in l:
        if i not in res:
            res.append(i)
            sum_s += i

    return sum_s


list1 = [3, 4, 1, 2, 5, 6, 6, 5, 4, 3, 3]

print(func(list1))  # 21

练习1

原文:https://www.cnblogs.com/yafeng666/p/12146953.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!