import fuckit
from string import ascii_lowercase, digits
from random import choice, randint
def defuckify(test_fn, fn_name, n_arguments):
''' Randomly generate functions until the test passes
'''
defuckified_fn = ('def %s(' % fn_name)
for i in range(n_arguments):
arg_name = ('arg%d,' % i) if i != n_arguments else ('arg%d' % i)
defuckified_fn += arg_name
defuckified_fn += '):'
exec('def '+ fn_name + '():\n pass\n')
while not test_fn():
for i in range(randint(100,10000)):
defuckified_fn += choice(' \n,[](){}\'"=+-*/%:'+ ascii_lowercase + digits)
with fuckit:
exec(defuckified_fn)
print(defuckified_fn)
Edited to use fuckit instead of try/catchEdited again to add that it has been over an hour and it hasn't been able to make a function that returns 3