954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

operator/function for a list of letters

Hello to all!How can i make a list from all the small letters of the alphabet without writing every one?Is there an operator/function that does that,something like ['a'-'z'].I've tried in many ways but i'm new in Python and if there is that operator i haven't discover it yet.My appreciation!

coder_gus
Newbie Poster
9 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

This will do it ...

print "Fill a string with a - z:"
alphaStr = ""
# letters a to z are ASCII code 97 to 122
for k in range(97, 123):
  alphaStr += chr(k)

print alphaStr

# if you don't have an ASCII table handy let Python do it ...
print "ord('a') =", ord('a')
print "ord('z') =", ord('z')
vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

Hi!

Python comes with batteries included ;)

>>> import string
>>> string.lowercase
'abcdefghijklmnopqrstuvwxyz'


Regards, mawe

mawe
Junior Poster
133 posts since Sep 2005
Reputation Points: 19
Solved Threads: 58
 

Thanks mawe, welcome to this tiny Python corner. So a simple ...

import string
alphaStr = string.lowercase

print alphaStr

... would have done it. I guess it pays to run ...

help('string')

Thanks again!

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

Thanks for the welcome. It's a nice community here :)

mawe
Junior Poster
133 posts since Sep 2005
Reputation Points: 19
Solved Threads: 58
 

Thanks a lot guys.It's great to know that we can help each other once in a while.

coder_gus
Newbie Poster
9 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You