Joh*_*ooy 168
>>> import string
>>> string.ascii_lowercase[:14]
'abcdefghijklmn'
>>> string.ascii_lowercase[:14:2]
'acegikm'
Run Code Online (Sandbox Code Playgroud)
要做网址,你可以使用这样的东西
[i + j for i, j in zip(list_of_urls, string.ascii_lowercase[:14])]
Run Code Online (Sandbox Code Playgroud)
Nas*_*nov 44
假设这是一个家庭作业;-) - 不需要召唤库等 - 它可能希望你使用chr/ord的range(),如下所示:
for i in range(ord('a'), ord('n')+1):
print chr(i),
Run Code Online (Sandbox Code Playgroud)
对于其余的,只需使用范围()玩一点
Way*_*ner 22
提示:
import string
print string.ascii_lowercase
Run Code Online (Sandbox Code Playgroud)
和
for i in xrange(0, 10, 2):
print i
Run Code Online (Sandbox Code Playgroud)
和
"hello{0}, world!".format('z')
Run Code Online (Sandbox Code Playgroud)
Mar*_*oma 10
small_letters = map(chr, range(ord('a'), ord('z')+1))
big_letters = map(chr, range(ord('A'), ord('Z')+1))
digits = map(chr, range(ord('0'), ord('9')+1))
Run Code Online (Sandbox Code Playgroud)
要么
import string
string.letters
string.uppercase
string.digits
Run Code Online (Sandbox Code Playgroud)
此解决方案使用ASCII表.ord从字符中获取ascii值,chr反之亦然.
>>> small_letters = map(chr, range(ord('a'), ord('z')+1))
>>> 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
>>> print(" ".join(small_letters[0::2]))
a c e g i k m o q s u w y
>>> s = small_letters[0:(ord('n')-ord('a')+1):2]
>>> print(" ".join(s))
a c e g i k m
>>> urls = ["hello.com/", "hej.com/", "hallo.com/"]
>>> print([x + y for x, y in zip(urls, an)])
['hello.com/a', 'hej.com/b', 'hallo.com/c']
Run Code Online (Sandbox Code Playgroud)
小智 7
import string
print list(string.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']
Run Code Online (Sandbox Code Playgroud)
小智 5
import string
print list(string.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']
Run Code Online (Sandbox Code Playgroud)
和
for c in list(string.ascii_lowercase)[:5]:
...operation with the first 5 characters
Run Code Online (Sandbox Code Playgroud)
小智 5
myList = [chr(chNum) for chNum in list(range(ord('a'),ord('z')+1))]
print(myList)
Run Code Online (Sandbox Code Playgroud)
输出
['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']
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
211768 次 |
| 最近记录: |