By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 906 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

Help writing a loop

Thekid
100+
P: 145
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:
Expand|Select|Wrap|Line Numbers
  1. for i in range(10):
  2.    for j in range(10):
  3.      for k in range(10):
  4.         print i,j,k
  5.  
May 21 '09 #1
Share this Question
Share on Google+
2 Replies


dshimer
Expert 100+
P: 136
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.

Expand|Select|Wrap|Line Numbers
  1. for i in range(65,70):
  2.     for j in range(65,70):
  3.         for k in range(65,70):
  4.             print chr(i),chr(j),chr(k)
  5. ...             
  6. A A A
  7. A A B
  8. A A C
  9. A A D
  10. A A E
  11. A B A
  12. A B B
  13. A B C
  14. A B D
  15.  
  16.  
May 21 '09 #2

Thekid
100+
P: 145
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.
May 21 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.