首页 > 解决方案 > 问题是来自hackerrank的匹配销售

问题描述

为什么函数 dupli 无法从列表中删除所有重复元素以获得更大的值。

 #value for N =42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 
 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 
 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 
 42 42 42 42 42 42 42 42 42 42 42


n=int(input())
N=list(map(int,input().split()))

def dupli(a):
    for i in N:
        if i==a:
           N.remove(i)

f=[]
for i in N:

a=N.count(i)
dupli(i)

f.append(a//2)
s=0
for i in f:
    s+=i
print(s)

标签: python-3.x

解决方案


推荐阅读