如何在不使用if语句的情况下编写此代码

时间:2016-10-15 11:30:08

标签: python if-statement

def in_puzzle_horizontal(puzzle, word):

    left_right = lr_occurrences(puzzle, word)
    right_left = lr_occurrences((rotate_puzzle(rotate_puzzle(puzzle))), word) 
    total = left_right or right_left

    if total > 0:
        return True
    else: 
        return False

2 个答案:

答案 0 :(得分:6)

您只需将if语句替换为:

return total > 0

答案 1 :(得分:1)

left_right = lr_occurrences(puzzle, word)
right_left = lr_occurrences((rotate_puzzle(rotate_puzzle(puzzle))), word)
total = left_right or right_left
return total > 0