像excel一样的Python字符串序列

标签 python python-3.x

我想要像 excel 标题一样的序列。

例如: A,B,C,..,Z,AA,AB....

我的代码

>>> s = 'A'
>>> chr(ord(s) + 1)
'B'
>>> s = 'Z'
>>> chr(ord(s) + 1)  
'['
>>> 
# I want AA after chr(ord('Z') + 1)

最佳答案

使用 itertools,

import itertools

alpha = [chr(x) for x in range(65, 91)] # create a list of character's

print(alpha + [k + v for k,v in itertools.product(alpha, repeat=2)])

关于像excel一样的Python字符串序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62126326/

相关文章:

python - Django-rest-framework @detail_route 用于特定网址

python - 使用 python 连接到 Outlook 并读取电子邮件和附件,然后将其写入输出文件

python - 我怎么能不计算字符串之间的空格

python - 对 Python3 中特定类的实例进行赋值深复制

Python H2O直方图错误: bar() missing 1 required positional argument: 'x'

python - 随机化整数行为

python - 导入非打包模块的python类

python - 子类构造函数抛出 TypeError : __init__() takes 2 positional arguments but 5 were given

python - "if"语句查找剩余数字并附加到 csv 列表中

python - 查询时出现AttributeError : Neither 'InstrumentedAttribute' object nor 'Comparator' has an attribute