python比较两个列表中不同的数、保存在,如何在Python中比较数组中的值-找出2个值是否相同...

I basically have an array of 50 integers, and I need to find out whether any of the 50 integers are equal, and if they are, I need to carry out an action.

How would I go about doing this? As far as I know there isn't currently a function in Python that does this is there?

解决方案

If you mean you have a list and you want to know if there are any duplicate values, then make a set from the list and see if it's shorter than the list:

if len(set(my_list)) < len(my_list):

print "There's a dupe!"

This won't tell you what the duplicate value is, though.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值