Skip to content

Instantly share code, notes, and snippets.

@stephengruppetta
Created May 7, 2023 09:24
Show Gist options
  • Save stephengruppetta/29c250d0a87984e6fefb87d69da85293 to your computer and use it in GitHub Desktop.
Save stephengruppetta/29c250d0a87984e6fefb87d69da85293 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
# standard dice with 6 sides
roll_standard_dice = functools.partial(roll_dice, 6)
print(roll_standard_dice.func)
# <function roll_dice at 0x102ab0720>
print(roll_standard_dice.args)
# (6,)
print(roll_standard_dice.keywords)
# {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment