基本的に、リストに複数のモードがあるかどうかに関係なく、Python のリストからモード (最も頻繁に発生する番号) を生成する方法を理解する必要があります。
このようなもの:
def print_mode (thelist):
counts = {}
for item in thelist:
counts [item] = counts.get (item, 0) + 1
maxcount = 0
maxitem = None
for k, v in counts.items ():
if v > maxcount:
maxitem = k
maxcount = v
if maxcount == 1:
print "All values only appear once"
if counts.values().count (maxcount) > 1:
print "List has multiple modes"
else:
print "Mode of list:", maxitem
しかし、「すべての値は一度だけ表示されます」または「リストには複数のモードがあります」で文字列を返す代わりに、参照している実際の整数を返したいですか?