gpt4 book ai didi

python - 读取一行或 idk 时的 EOF

转载 作者:太空宇宙 更新时间:2023-11-03 20:11:48 25 4
gpt4 key购买 nike

我只是在做一个执行以下操作的程序。

  1. 您输入某物的“计数”。
  2. 然后为每个“计数”输入一个值,并用空格分隔
  3. 您将得到输出:其中有多少是重复的,哪个重复的数字最高,再次用空格分隔

基本上是这样的:输入:

8           
12 12 16 102 47 16 102 47

输出:

4 102

问题是我的代码没有得到任何一点,我不知道问题出在哪里。在我的 python 中有效,但在某些在线编译器中无效,因此接收者可能与我的程序存在与在线站点相同的问题

def thing():
global count
count = int(input('n:'))
if count > 100000:
exit()
elif count < 1:
exit()
else:
wut()
def wut():
idk = []
inp = list(map(int,input('ai:').split(' ')))
if len(inp) != count:
exit()
elif sum(inp) > 200000:
exit()
elif sum(inp) < 1:
exit()
else:
for i in range(len(inp)):
for x in range(i+1, len(inp)):
if inp[i] == inp[x]:
idk.append(inp[i])
o = len(idk)
idk.sort(reverse = True)
print(o, idk[0])

thing()

在我的 python 3.7.4 中,它工作得很好,但我没有得到任何一点。

最佳答案

from collections import Counter

# Convert them all to an int
numbers = [int(i) for i in input("Numbers: ").split(" ")]

# Get number of input
count = len(numbers)

counter = Counter(numbers)

# Get the highest value of the most common values
max_dup, _ = max(counter.most_common(), key=lambda ele: ele[0])

# Get the amount of duplicates
dups = len(list(filter(lambda k: k[1] > 1, counter.items())))

print(dups, end=" ")

print(max_dup)

collections.Counter filter

关于python - 读取一行或 idk 时的 EOF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58672542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com