[英]Print i prints repeated number twice, is there any method for printing it only once
This is my code这是我的代码
tup = (1,2,3,4,5,6,6)
for i in tup:
if (tup.count(i)<1):
print(i)
And it's output is它的 output 是
6
6
But i want it's output should only prints once.但我希望它的 output 应该只打印一次。 What logic do I need to add and why it's printing twice?
我需要添加什么逻辑以及为什么要打印两次?
import collections
print([item for item, count in collections.Counter(tup).items() if count > 1])
in this case it is printing twice, because it is iterating every element in your TUP and there are two 6 es, and 6 is more than 1在这种情况下,它打印了两次,因为它正在迭代 TUP 中的每个元素,并且有两个 6 es,并且 6 大于 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.