This is a pretty simple task i feel like i should be able to do- but just for the life of me, cant figure out.
I'm trying to write a recursive function to replicate the following:
chars = '0123456789abcdef'
for a in chars:
for b in chars:
for c in chars:
for d in chars:
print a+b+c+d
searching for an example hasn't proven very fruitful.
code thats not working:
chars = 'ABCDEF'
def resu(chars, depth = len(chars)):
for char in chars:
if depth == 0:
return char
return char + resu(chars, depth - 1)
print resu(chars)
You don't need recursion if you have itertools
:
from itertools import product
for a,b,c,d in product('abc', repeat=4):
print a+b+c+d
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With