-2

Is there a built in list in python or some package that has a list of the alphabets? I would like to avoid a system such as

alphabets = ('a','b','c',.....)
arifyali
  • 385
  • 1
  • 3
  • 6
  • Why was my question downvoted? – arifyali Nov 02 '13 at 21:41
  • 7
    because you clearly haven't even googled it. – Dunno Nov 02 '13 at 21:42
  • 6
    The first google result for `python alphabet` is [this question](http://stackoverflow.com/questions/16060899/alphabet-range-python). The third was the documentation for the `string` module. – DSM Nov 02 '13 at 21:43

2 Answers2

10

Use string.ascii_lowercase:

>>> from string import ascii_lowercase
>>> ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'
>>> list(ascii_lowercase)
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504
  • 1
    Why would anyone downvote this answer?!? +1 from me to compensate. Please do the same... – dawg Nov 02 '13 at 21:52
3

You can also do a list comprehension:

>>> [chr(i) for i in range(97,97+26)]
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
dawg
  • 98,345
  • 23
  • 131
  • 206
  • Thanks for providing an alternate way to implement this. I am new to Python and I had not yet learned what a list comprehension is, so this helped me understand both list comprehensions and the answer to my original question, but I accepted the other one as my answer because it is simpler to maintain and to understand, but thank you still! :) – arifyali Nov 02 '13 at 22:00
  • 2
    @ArifAli: Actually, you choose the right answer as 'the answer' for this. You should use `ascii_lowercase` in preference to generating these constants. I just showed this as an alternative. Glad it was of educational value to you! – dawg Nov 02 '13 at 23:19