码迷,mamicode.com
首页 > 其他好文 > 详细

练习1

时间:2020-01-03 22:58:25      阅读:60      评论:0      收藏:0      [点我收藏+]

标签:有一个   UNC   print   sum   color   not   fun   res   int   

‘‘‘有一个列表[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

标签:有一个   UNC   print   sum   color   not   fun   res   int   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!