> possible = "234567abcdefghijklmnopqrstuvwxyz"
> word_length = 16
> print 'Running "every.py"'
> word_list = []
> def add_word(word):
>     if len(word)==word_length:
>         word_list.append(word)
>         print word
>     else:
>         for c in possible:
>             new_word = word + c
>             add_word(new_word)
>
>
> The only problem with this code is that it actually takes a word as its
> input and just checks that it is == word length. If not it just appends
> the
> string possible to the variable word that was called in the function
> add_word.
>
> I need to be able to generate every possible combination of the characters
> in the variable possible, ideally coming up with a string that resembles
> the TOR hidden network strings that look like this:
> "kpvz7ki2v5agwt35.onion"
>
>
> Scott

Actually it doesn't even do that. It only prints "running 'every.py'"!
You forgot the line that does all the work:
"""
add_word("")
"""
I'm attaching the whole file so you don't miss the important bit.
Run it and see what happens, but be ready to CNTL-C (I'm assuming you are
running Linux, I think it'll be the same on Mac, all bets are off
regarding M$ Windoz:-)


Alex
#!/usr/bin/env python

# file :  every.py
print 'Running "every.py"'

possible = "234567abcdefghijklmnopqrstuvwxyz"
word_length = 16

word_list = []
def add_word(word):
    if len(word)==word_length:
        word_list.append(word)
        print word   # There may come a time you won't want this line.
    else:
        for c in possible:
            new_word = word + c
            add_word(new_word)

add_word("")

# print word_list
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to