有人能帮我把这个函数写在一行吗?

2024-04-25 13:32:45 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的解决办法。不雅观。请帮忙。你知道吗

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

Tags: ofthekeyinnumberdefkeyslength