目标是找出一个长数字中最常见的数字。例如,213523432455555555将返回5.
print('Question 4')
def most_frequent(number):
analysisnumber=map(int,str(number))
returnvalue=[0,0,0,0,0,0,0,0,0,0]
highest = 0
total2=0
for i in range(0,len(str(number))):
returnvalue[analysisnumber[i]] = list(map(i,analysisnumber))
for i in range(0,20):
if i < 10:
if returnvalue[i] > highest:
highest = returnvalue[i]
if i > 10:
if returnvalue[i-10] == highest:
total2+=highest
print("The most frequent number",end="")
if total2 > highest:
print("s are: ")
for i in range(0,10):
if returnvalue[i] == highest:
print(i)
else:
print(" is ", end="")
for i in range(0,10):
if returnvalue[i] == highest:
print(i)
break
number=int(input("Enter the number intended for analysis:"))
most_frequent(number)
我得到了
TypeError: 'int' object is not callable
错误。会爱一些帮助!
答案 0 :(得分:6)
这样做,使用Counter:
>>> c.most_common(1)
[('2', 5)]
或者只是使用(感谢@tobias_k):
Monitor Cassandra for memory consumption and stage throughput.
Set your Memtable thresholds low.
Access Cassandra concurrently.
Don’t store all your data in a single row.
Check for time-outs.
What is the size of javaHeap?
答案 1 :(得分:5)
你正在使用错误的地图功能。
returnvalue[analysisnumber[i]] = list(map(i,analysisnumber))
要映射的第一个值(来自文档)是函数):map(function, iterable, ...)
你提供了一个int(i)。