ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 22 Mar 2021 18:04:42 +0100Is it possible to extend the latin alphabet to AA, AB, AC....https://ask.sagemath.org/question/56315/is-it-possible-to-extend-the-latin-alphabet-to-aa-ab-ac/ Perhaps one more time a stupid question or a Python one.
cand=build_alphabet(name="upper")
show(cand)
can list all letter in latin alphabet. But is there a possibility to construct extended alphabet as `AA, AB, AC,...,AZ, BA,...` as in Excel cellsMon, 22 Mar 2021 16:19:40 +0100https://ask.sagemath.org/question/56315/is-it-possible-to-extend-the-latin-alphabet-to-aa-ab-ac/Answer by slelievre for <p>Perhaps one more time a stupid question or a Python one.</p>
<pre><code>cand=build_alphabet(name="upper")
show(cand)
</code></pre>
<p>can list all letter in latin alphabet. But is there a possibility to construct extended alphabet as <code>AA, AB, AC,...,AZ, BA,...</code> as in Excel cells</p>
https://ask.sagemath.org/question/56315/is-it-possible-to-extend-the-latin-alphabet-to-aa-ab-ac/?answer=56316#post-id-56316Using `build_alphabet` is on the right track.
Words on that alphabet are a natural next step and provide exactly
what is needed.
Define a function `labels` taking as an argument the desired number:
def labels(n):
W = FiniteWords(build_alphabet(name='upper'))
AZZ = (w for k in PositiveIntegers() for w in W.iterate_by_length(k))
return [str(next(AZZ)) for _ in range(n)]
Use it to build a list of 60 labels:
sage: print(labels(60))
['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', 'AA', 'AB',
'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN',
'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ',
'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH']Mon, 22 Mar 2021 18:04:42 +0100https://ask.sagemath.org/question/56315/is-it-possible-to-extend-the-latin-alphabet-to-aa-ab-ac/?answer=56316#post-id-56316