I dont think I've explained the my needs properly. I would like to actually check each value of one var with its parent. So if n2 should be tested from 1 to 500 with 1 of n1.
This does not at all explain your needs. I understand that you want to test a certain property for a certain set of values. There must be a way to describe more precisely this set of values as well as the property.
I'll try my best. Imaging we're making a game where the computer has to guess a word. And it needs to use brute force. So if the word is "hey".
I would use 3 for loops each with its own var as an alphabet so in the parent loop it would test 'A' with A-Z of the second loop and in the third loop it would test 'AA' with A-Z.
word = 'hey'
for n1 in range(1, 129):
char = chr(n1)
if(char == word):
print 'word is' + char
for n2 in range(1, 129):
char2 = chr(n1)
if(char+char2 == word):
print 'word is' + char1 + char2
for n3 in range(1, 129):
char3 = chr(n1)
if(char+char2+char3 == word):
print 'word is' + char1 + char2 + char3
I know the code is crude I just put it up fast.
For a 3 letter word this word suffice but for word which has n number of alphabets what would you do ?
def brute(items, n):
"""generate tuples of len 1 to n with items chosen in a given sequence"""
items = list(items)
for k in range(1, n+1):
for t in itertools.product(items, repeat = k):
for t in brute(range(97, 100), 3):
word = ''.join(chr(x) for x in t)