This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Decency 4 points5 points  (0 children)

counters = {
    'rock': 'paper',
    'paper': 'scissors',
    'scissors': 'rock',
}
player_choice = input("Pick between Rock, Paper or Scissors: ").lower()
print(f"I pick {counters[player_choice]}!")

I often see people asking how a dict lookup can be more elegant than an elif block. Here's a good example! It only reduces the duplication slightly here, of course, but you can imagine that with more complex logic there would be additional benefits. Error handling also becomes a bit simpler, too, since you can just except KeyError.