How to make a continuous alphabetic list python (from a-z then from aa, ab, ac etc)

前端 未结 6 1206
时光取名叫无心
时光取名叫无心 2020-11-30 08:53

I would like to make a alphabetical list for an application similar to an excel worksheet.

A user would input number of cells and I would like to generate list. For

6条回答
  •  温柔的废话
    2020-11-30 09:43

    I've ended up doing my own. I think it can create any number of letters.

    def AA(n, s):
        r = n % 26
        r = r if r > 0 else 26
        n = (n - r) / 26
        s = chr(64 + r) + s
    
        if n > 26: 
            s = AA(n, s)
        elif n > 0:
            s = chr(64 + n) + s
    
        return s
    

    n = quantity | r = remaining (26 letters A-Z) | s = string

    To print the list :

    def uprint(nc):
        for x in range(1, nc + 1):
            print AA(x,'').lower()
    

    Used VBA before convert to python :

    Function AA(n, s)
    
        r = n Mod 26
        r = IIf(r > 0, r, 26)
        n = (n - r) / 26
        s = Chr(64 + r) & s
    
        If n > 26 Then
            s = AA(n, s)
        ElseIf n > 0 Then
            s = Chr(64 + n) & s
        End If
    
        AA = s
    
    End Function
    

提交回复
热议问题