Skip to content

Instantly share code, notes, and snippets.

@stephengruppetta
Created May 7, 2023 09:29
Show Gist options
  • Save stephengruppetta/b4c8d74843eb312b7967a9dc351f1673 to your computer and use it in GitHub Desktop.
Save stephengruppetta/b4c8d74843eb312b7967a9dc351f1673 to your computer and use it in GitHub Desktop.
import functools
import random
def roll_dice(max_value, number_of_dice):
return [
random.randint(1, max_value)
for _ in range(number_of_dice)
]
# Create a partial object that always rolls
# two standard dice with 6 sides
roll_monopoly_dice = functools.partial(roll_dice, 6, 2)
print(roll_monopoly_dice.func)
# <function roll_dice at 0x102ab0720>
print(roll_monopoly_dice.args)
# (6, 2)
print(roll_monopoly_dice.keywords)
# {}
print(roll_monopoly_dice())
# [5, 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment