-1

How can I print the alphabet on one line using chr(), with each letter seperated by a space.

My current code:

for x in range(97,123):
    letter = chr(x)
    alphabet = "" + letter
    print alphabet
user2989433
  • 53
  • 1
  • 6

2 Answers2

3
import string
print " ".join(string.lowercase)

Or if the use of chr is mandatory, as mentioned in the comments:

print " ".join([chr(c) for c in xrange(ord('a'), ord('z') + 1)])
Matt
  • 17,290
  • 7
  • 57
  • 71
  • I must admit your 1st solution is cool - I don't think I've ever noticed `.join()` being used with a string argument before, but of course it makes perfect sense, since strings are iterable. – PM 2Ring Nov 05 '14 at 13:37
1

Use , after print statement so that

print alphabet,
Vishnu Upadhyay
  • 5,043
  • 1
  • 13
  • 24