String - Python - How To Print Range A-Z - Stack Overflow
String - Python - How To Print Range A-Z - Stack Overflow
- Stack Overflow
How are we doing? Please help us improve Stack Overflow. Take our short survey
1. Print a-n: a b c d e f g h i j k l m n
3. Append a-n to index of urls{hello.com/, hej.com/, ..., hallo.com/}: hello.com/a hej.com/b ...
hallo.com/n
39
python string list ascii
6 Odd that to a "beginner" question you can still get a variety of answers. The fact that I can type does not
mean that I can "python", I really like gnibbler's answer over for-messy-things. Thanks everyone for your
answers and -- keep things simple, special thanks to gnibbler. – hhh Dec 23 '10 at 2:06
2 It's not a wild variety of answers. It's two varieties. One use range and chr() and another the ready
made lists in string , which many people wouldn't think of. – Lennart Regebro Dec 25 '10 at 8:45
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
1 I believe string.ascii_lowercase already worked in python 2.x, so to be sure just always use
our Terms of Service.
ascii_lowercase. – johk95 Aug 23 '17 at 11:32
https://stackoverflow.com/questions/3190122/python-how-to-print-range-a-z 1/8
9/4/2020 string - Python: how to print range a-z? - Stack Overflow
1 @johk95, actually str.lowercase is locale dependent so wasn't the best choice in the first place. I've
Hi, would be able to tell me whether is this only available in English? cant I get the same for other
languages as well? Thanks & Best Regards – Michael Schroter Apr 13 at 6:17
Assuming this is a homework ;-) - no need to summon libraries etc - it probably expect you to use
range() with chr/ord, like so:
48
for i in range(ord('a'), ord('n')+1):
print chr(i),
For the rest, just play a bit more with the range()
Hints:
23 import string
print string.ascii_lowercase
and
and
"hello{0}, world!".format('z')
or
import string
string.letters
string.uppercase
string.digits
This solution uses the ASCII table. ord gets the ascii value from a character and chr vice versa.
>>> an = small_letters[0:(ord('n')-ord('a')+1)]
>>> print(" ".join(an))
a b c d e f g h i j k l m n
>>> s = small_letters[0:(ord('n')-ord('a')+1):2]
>>> print(" ".join(s))
a c e g i k m
It looks like string.letters was removed in Python 3 and only string.ascii_letters, not exactly the same, is
available – jonespm Feb 7 '19 at 17:50
import string
print list(string.ascii_lowercase)
8 # ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
By using our site,
's', you 'u',
't', acknowledge that
'v', 'w', you'y',
'x', have 'z']
read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.
https://stackoverflow.com/questions/3190122/python-how-to-print-range-a-z 3/8
9/4/2020 string - Python: how to print range a-z? - Stack Overflow
Mikhail Makeev
140 2 5
import string
print list(string.ascii_lowercase)
6 # ['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']
and
for c in list(string.ascii_lowercase)[:5]:
...operation with the first 5 characters
['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']
Welcome to StackOverflow. Try to explain more clearly why this is a complete answer to the question. –
Jeroen Heier Sep 6 '19 at 11:11
#1)
print " ".join(map(chr, range(ord('a'),ord('n')+1)))
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
2 Terms #2)
our of Service.
print " " join(map(chr range(ord('a') ord('n')+1 2)))
https://stackoverflow.com/questions/3190122/python-how-to-print-range-a-z 4/8
9/4/2020 string - Python: how to print range a-z? - Stack Overflow
print .join(map(chr, range(ord( a ),ord( n )+1,2)))
#3)
urls = ["hello.com/", "hej.com/", "hallo.com/"]
an = map(chr, range(ord('a'),ord('n')+1))
print [ x + y for x,y in zip(urls, an)]
The answer to this question is simple, just make a list called ABC like so:
2 ABC = ['abcdefghijklmnopqrstuvwxyz']
ABC = ['abcdefghijklmnopqrstuvwxyz']
try:
while True:
for a in ABC:
for b in ABC:
for c in ABC:
for d in ABC:
for e in ABC:
for f in ABC:
print a, b, c, d, e, f, ' ',
except KeyboardInterrupt:
pass
Try:
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.
2 strng = ""
https://stackoverflow.com/questions/3190122/python-how-to-print-range-a-z 5/8
9/4/2020 string - Python: how to print range a-z? - Stack Overflow
strng
for i in range(97,123):
1 import string
alphas = list(string.ascii_letters[:26])
for chr in alphas:
print(chr)
0 Zip -function, full explanation, returns a list of tuples, where the i-th tuple contains the i-th
element from each of the argument sequences or iterables. [...] construct is called list
comprehension, very cool feature!
list(string.ascii_lowercase)
0
By using our
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
site,
's', you 'u',
't', acknowledge that
'v', 'w', you'y',
'x', have 'z']
read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.
https://stackoverflow.com/questions/3190122/python-how-to-print-range-a-z 6/8
9/4/2020 string - Python: how to print range a-z? - Stack Overflow
DhiaTN townie
7,001 9 43 56 144 1 9
Another way to do it
0 import string
pass
aalist = list(string.ascii_lowercase)
aaurls = ['alpha.com','bravo.com','chrly.com','delta.com',]
iilen = aaurls.__len__()
pass
print(ans01)
print(ans02)
print(ans03)
pass
Result
abcdefghijklmn
acegikm
alpha.com/a
bravo.com/b
chrly.com/c
delta.com/d
alpha.com/e
bravo.com/f
chrly.com/g
delta.com/h
alpha.com/i
bravo.com/j
chrly.com/k
delta.com/l
alpha.com/m
bravo.com/n
cycle through the urls and do not stop until we run out of letters
edited
By using our site, you acknowledge that you have read andJun 12 '19 at 0:14
understand answered
our Cookie Policy Jun Policy
, Privacy 12 '19 ,atand
0:08
Highly active question. Earn 10 reputation in order to answer this question. The reputation requirement helps
protect this question from spam and non-answer activity.
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.
https://stackoverflow.com/questions/3190122/python-how-to-print-range-a-z 8/8