-4
這是我的解決方案。它不是優雅的。請幫忙。任何人都可以幫助我在一行中寫這個函數嗎?
def calculateHandlen(hand):
"""
Returns the length (number of letters) in the current hand.
hand: dictionary (string int)
returns: integer
"""
num = 0
keyS = hand.keys()
for key in keyS:
if hand[key] > 0:
num += hand[key]
return num
爲什麼你需要它在一條線?函數有什麼問題? –
爲什麼?這個功能很好。不要陷入思考「單行程」爲更優雅的代碼所製造的陷阱。 –
如果手[鍵]> 0:「長度(字母數)」給你' –