Codewars note: 石头剪刀布
Solution:
def rps(p1, p2): dict_wins = {('rock', 'scissors') : 'Player 1 won!', ('rock', 'paper'):'Player 2 won!', ('scissors', 'rock') : 'Player 2 won!', ('scissors', 'paper') : 'Player 1 won!', ('paper', 'rock') : 'Player 1 won!', ('paper', 'scissors'): 'Player 2 won!' } return dict_wins.get((p1,p2)) if (p1, p2) in dict_wins else 'Draw!'
:dict.get(key):获得字典 键 对应 的值
:itertools
.permutations()获得 没有重复的 有序组合
.combinations()
.combinations_with_replacement()
.product()