私の解決策です。エレガントではありません。助けてください。誰でもこの関数を1行に書くのを助けることができますか?
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
なぜ1行に入力する必要がありますか?関数に何が問題なのですか? –
なぜですか?この関数は、それが正しい方法です。より洗練されたコードを作るために、 "one-liners"という考えの罠に陥ってはいけません。 –
「長さ(文字数)」は、「手[キー]> 0: 'ならあなたはどうしますか? –