def most_common(dices):
"""
Returns the dices that are most common
In case of a draw, returns the lowest number
"""
counts = Counter(dices)
keep = max(counts.iteritems(), key=operator.itemgetter(1))[0]
return [keep] * counts[keep]
我對返回語法感到困惑。return statement confusion ..我不確定語法
什麼是
[keep]
?它看起來像一個沒有別的東西的數組支架。counts[keep]
看起來像vector_name[index]
。是對的嗎?
最後,爲什麼它會在return語句中乘以兩個值?感謝你的幫助。
可能是這樣'>>>升財產以後= [2] >>> [3] * L [0]''得到[3,3]'。 –