我们现在这儿: 丢人只解决了3道题目
-
就不按照原来的顺序了 有些题目暂时解决不了,下面按照已经解决的顺序更新答案
-
Non-unique Elements
题目要求:
解题思路:列表有一个count()方法 可以统计每个元素的个数,在加上列表推导式,所以答案呼之欲出咯
废话少说 上代码
def checkio(data: list) -> list:
# Your code here
# It's main function. Don't remove this function
# It's used for auto-testing and must return a result for check.
# 一行就搞定 利用列表推导式生成它需要的新列表 用count函数统计元素个数
return [i for i in data if data.count(i) > 1]
if __name__ == "__main__":
# These "asserts" using only for self-checking and not necessary for auto-testing
assert list(checkio([1, 2, 3, 1, 3])) == [1, 3, 1, 3], "1st example"
assert list