Help writing a loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Thekid
    New Member
    • Feb 2007
    • 145

    Help writing a loop

    I'm trying to figure out how to write a loop using 2 sets of values 'a-z' and 'A-Z' so it would look like this:
    aaaaaaaaaa
    aaaaaaaaaA
    aaaaaaaaAa
    aaaaaaaAaa
    and so on:
    aaaaaaaaAA
    aaaaaaaAAA
    and then moving on to b:
    bbbbbbbbbA

    I can do it using numbers but don't know how to do it with letters:
    Code:
    for i in range(10):
       for j in range(10):
         for k in range(10):
            print i,j,k
  • dshimer
    Recognized Expert New Member
    • Dec 2006
    • 136

    #2
    This almost seems to simplistic but how about something like this.

    Note that the range values and results are truncated and don't exactly match your requirements, just used the original example loop to show the general idea.

    Code:
    for i in range(65,70):
    	for j in range(65,70):
    		for k in range(65,70):
    			print chr(i),chr(j),chr(k)
    ... 			
    A A A
    A A B
    A A C
    A A D
    A A E
    A B A
    A B B
    A B C
    A B D

    Comment

    • Thekid
      New Member
      • Feb 2007
      • 145

      #3
      Ah.... I see. So simply using the chr() function will do it. Thanks!

      Edited:
      When I use that but change the ascii numbers to (97,122) and use 5 'for' loops,
      it will do:
      aaaaa
      aaaab
      and so on but I would need the Caps (65,90) to run through it. This method will take a long time to run through all of the combos, is there another way to do this quicker? Thanks.

      Comment

      Working...