Dec-19-2020, 07:30 AM
You don't necessarily need the nested function for that; you can use partial application with
partial
from the functools
module. Have create_password
take both parameters, characters
and length
:def create_password(characters, length): # Code as above
partial
allows you to freeze the arguments of a function, returning a function with a lower arity:from functools import partial alpha_password = partial(create_password, characters='abcdef') symbol_password = partial(create_password, characters='!@#$%')Both
alpha_password
and symbol_password
are functions that just take the length, as in your example.