
import string


def index_to_column_id(number):
    """
    Takes a zero-based index and converts it to a column identifier string
    such as used in Excel. Examples:
    0 => A
    25 => Z
    26 => AA
    """
    if number < 0 or not isinstance(number, int):
        raise AttributeError("index_to_column_id requires a non-negative int")
    digits = string.ascii_uppercase
    if number == 0:
        return digits[0]
    return __rec_int_to_colid(number, digits)


def __rec_int_to_colid(number, digits):
    base = len(digits)
    if number < 0:
        return ''

    return (
        __rec_int_to_colid((number // base) - 1, digits) +
        digits[number % base])


import string


def index_to_column_id(number):
    """
    Takes a zero-based index and converts it to a column identifier string
    such as used in Excel. Examples:
    0 => A
    25 => Z
    26 => AA
    """
    if number < 0 or not isinstance(number, int):
        raise AttributeError("index_to_column_id requires a non-negative int")
    digits = string.ascii_uppercase
    parts = []
    number += 1  # The algorithm works on 1-based input
    while number > 0:
        number, mod = divmod(number - 1, len(digits))
        parts.insert(0, digits[mod])
    return ''.join(parts)

Replace index_to_column_id with iterative fx
Replace index_to_column_id with iterative fx

The recursive one was neat but a bit too clever.
  
  import string
  
  
  def index_to_column_id(number):
      """
      Takes a zero-based index and converts it to a column identifier string
      such as used in Excel. Examples:
      0 => A
      25 => Z
      26 => AA
      """
      if number < 0 or not isinstance(number, int):
          raise AttributeError("index_to_column_id requires a non-negative int")
      digits = string.ascii_uppercase
+     parts = []
+     number += 1  # The algorithm works on 1-based input
-     if number == 0:
+     while number > 0:
-         return digits[0]
-     return __rec_int_to_colid(number, digits)
+         number, mod = divmod(number - 1, len(digits))
+         parts.insert(0, digits[mod])
+     return ''.join(parts)
  
- 
- def __rec_int_to_colid(number, digits):
-     base = len(digits)
-     if number < 0:
-         return ''
- 
-     return (
-         __rec_int_to_colid((number // base) - 1, digits) +
-         digits[number % base])
- 
Replace index_to_column_id with iterative fx
## Code Before:

import string


def index_to_column_id(number):
    """
    Takes a zero-based index and converts it to a column identifier string
    such as used in Excel. Examples:
    0 => A
    25 => Z
    26 => AA
    """
    if number < 0 or not isinstance(number, int):
        raise AttributeError("index_to_column_id requires a non-negative int")
    digits = string.ascii_uppercase
    if number == 0:
        return digits[0]
    return __rec_int_to_colid(number, digits)


def __rec_int_to_colid(number, digits):
    base = len(digits)
    if number < 0:
        return ''

    return (
        __rec_int_to_colid((number // base) - 1, digits) +
        digits[number % base])

## Instruction:
Replace index_to_column_id with iterative fx
## Code After:

import string


def index_to_column_id(number):
    """
    Takes a zero-based index and converts it to a column identifier string
    such as used in Excel. Examples:
    0 => A
    25 => Z
    26 => AA
    """
    if number < 0 or not isinstance(number, int):
        raise AttributeError("index_to_column_id requires a non-negative int")
    digits = string.ascii_uppercase
    parts = []
    number += 1  # The algorithm works on 1-based input
    while number > 0:
        number, mod = divmod(number - 1, len(digits))
        parts.insert(0, digits[mod])
    return ''.join(parts)
