简体   繁体   English

打印我重复打印两次,有什么方法只打印一次

[英]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.

相关问题 我的 python output 打印了两次,而我希望它打印一次 - My python output is printing out twice and while I want it to print out once 我想一次添加一个值,但是要添加两次,如果我先打印该值,它只会被添加一次 - I want to add a value once but gets added twice and if i print the value first it only gets add once 我的代码为每一行打印“未找到”,如果搜索不成功,我如何让它只打印一次“未找到”? - My code prints “Not Found” for every line, how do i get it to only print “Not Found” once if the search is unsuccessful? Python正在打印所有内容,我只希望它打印最后一个数字 - Python is printing everything, I only want it to print the last number 通过 for 循环时,如果变量为真,则打印两次,为假时仅打印一次 - When going through a for loop, if the variable is true it prints twice when it false it only prints once 如何使用我的 len() 仅在字典中打印我的项目一次而不打印数字 9、9 次 - How to print out my items in my dictionary only once with my len() without it printing the number 9, 9 times Python - deq 函数打印 8 次 - 防止只打印一次? - Python - deq function prints out 8 times - prevent to print only once? 我只需要打印一次,因为我在python中使用正则表达式将它打印了两次 - i need to print only once as i am getting it printed twice using regex in python 如何从excel sheet2中的excel sheet1打印数字并且重复的数字只能打印一次? - How can I print numbers from excel sheet1 that are there in excel sheet2 and that too repeated numbers must print only once? 我想在我的文本文件中打印以特定许可证号开头的行,但这仅在许可证号在第一行时才会打印出来 - I want to print the line in my textfile that starts with a specific license number, but this only prints out if the license number is in the 1st line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM