Hi All,

I want to create a pattern like this using python..

Aa0Aa1Aa2Aa3Aa4Aa5......Ab0Ab1Ab2.........and so on.


This may help

>>> import string
>>> print "Aa" + "Aa".join(string.digits)

Edited 5 Years Ago by Gribouillis: n/a

Well thanks Gribouillis for reply.But i am trying to generate a pattern like this..

chars1= "ABCDEFGHIJ...."
chars1= "abcdefghij..."
chars1= "01234567890"

I wanna specify a length and the script should generate a pattern like.

if a user specify a length 15.then the prog should generate only following.


It's a piece of cake for itertools

from itertools import islice, product, chain
import string

print ''.join(tuple(islice(chain.from_iterable(product(string.ascii_uppercase, string.ascii_lowercase, string.digits)), 79)))

""" my output -->

Notice that the maximum length is 20280 and this code will not complain if you replace 79 with 25000 but it will return a string of length 20280. An alternative is to store the 20 KB string somewhere and slice it directly: pattern20KB[:79]

Edited 5 Years Ago by Gribouillis: n/a

Thanks Man..

As you have fixed length pattern it is not difficult to produce from generator expression without modules

>>> st = ''.join(''.join((a,b,c))
...  for a in string.ascii_uppercase
... for b in string.ascii_lowercase
... for c in string.digits)
>>> len(st)
This question has already been answered. Start a new discussion instead.