如何以允许两位数的特定顺序创建字母数字网格?

How to create an alphanumeric grid in a certain sequence allowing double digit numbers?

我有一个网格特征 class,其大小和形状各不相同。我的测试 shapefile 是一个 3x4 网格。我需要创建一个按特定顺序排列的字母数字序列,但可以针对不同大小的网格进行缩放。以下是网格的顺序:

A4 | B4 | C4
A3 | B3 | C3
A2 | B2 | C2
A1 | B1 | C1

并且要使用这个字母数字序列,需要按特定顺序打印列表(从 table 的左下角开始,向右移动,然后返回到左值下一行: A1, B1, C1, A2, B2, C2, A3, B3, C3, A4, B4, C4

我有这个:

from itertools import product
from string import ascii_uppercase, digits

for x, y in product(ascii_uppercase, digits):
    print('{}{}'.format(x, y))

它生成如下序列:A0 到 A9,然后是 B0 到 B9,依此类推。 但是,我还需要更大的网格,因此如果网格大于 9 高,脚本必须进行补偿并允​​许序列在 9 之后使用两位数。 IE。 A10、B10、C10

然后我尝试制作 2 个列表,然后将它们组合在一起,但我 运行 遇到了按我需要的顺序加入这些列表的问题。

w = 3
h = 4

alpha = []
numeric = []
for letter in ascii_uppercase[:w]:
    alpha.append(letter)

for num in range(1, h+1):
    numeric.append(num)

我想我可能不需要制作一个数字列表,但不知道该怎么做。我知道的不仅仅是 python 的基础知识,还创建了如此复杂的脚本,但这真的让我感到困惑!我觉得我已经很接近了,但是从我上面的两个样本中遗漏了一些非常简单的东西。谢谢你能给我的任何帮助!

已解决,这是我为可能需要使用我的问题的其他人准备的:

w = 9
h = 20

alpha = []
numeric = []
for letter in ascii_uppercase[:w]:
    alpha.append(letter)

for num in range(1, h+1):
    numeric.append(num)

longest_num = len(str(max(numeric)))
for y in numeric:
    for x in alpha:
        print '{}{:0{}}'.format(x, y, longest_num)

我不需要格式为 table 的代码,因为我要在 ArcMap 中执行字段计算。

计算 numeric 后,还要执行:

longest_num = len(str(max(numeric)))

并将您的格式语句更改为:

'{}{:0{}}'.format(x, y, longest_num)

这确保当您达到两位数时,您会得到以下结果:

A12 | B12 | C12
A11 | B11 | C11
...
A02 | B02 | C02
A01 | B01 | C01

要实际打印网格,您需要更改代码:

longest_num = len(str(max(numeric)))
for y in reversed(numeric):
    print(" | ".join('{}{:0{}}'.format(x, y, longest_num)
                     for x in alpha))