Hi All,

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

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


Recommended Answers

All 5 Replies

This may help

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

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]

commented: Thanks Man.. +3

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)

Thanks Gribouillis and pytony for help..This is what i wanted!!!Thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.