[Tutor] All possible 16 character alphanumeric strings?

Scurvy Scott etanes.rm at gmail.com
Sun Sep 16 00:50:46 CEST 2012

Hello again python tutor list.
I have what I see as a somewhat complicated problem which I have no idea
where to begin. I'm hoping you fine folks can help me.

I'm trying to generate a list of every possible 16 character string
containing only 2-7 and a-z lowercase. I've seen some examples using regex
to define which characters I want to use but not a way to generate the
complete list of all possibilities. I'm not looking for a handout- just a
point in the right direction.

Any information would be awesome, thanks.

Right now I've got something like:

import random
>>> ''.join(random.choice('234567abcdefghijklmnopqrstuvwxyz') for i in range(16))

Which only prints 1 number, obviously.

or possibly something like this:

def genKey():
    hash = hashlib.md5(RANDOM_NUMBER).digest().encode("base32")
    alnum_hash = re.sub(r'[^a-z2-7]', "", hash)
    return alnum_hash[:16]

Keeping in mind that although I understand this code, I did not write it, I
got it from stackoverflow.

Again any help would be great. Feel free to ask if you must know exactly
what I'm trying to do.

I'm running Ubuntu 12.04 and python 2.7

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120915/28673a9c/attachment.html>

More information about the Tutor mailing list