Hi All,


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

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

Thanks...

Recommended Answers

All 5 Replies

This may help

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

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.
Aa0Aa1....Aa9Ab0Ab1....Ab9

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

Aa0Aa1Aa2A

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 -->
Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5A
"""

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)
20280
>>>

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, networking, learning, and sharing knowledge.