A to Z Sequence Generator with Repetition

  • Share this:

Code introduction


This function creates a generator that produces a sequence of letters from 'A' to 'Z', repeating this sequence n times. It utilizes Python's string and character encoding.


Technology Stack : String, character encoding

Code Type : Generator function

Code Difficulty : Intermediate


                
                    
def a_to_z_sequence(n):
    """
    Generate a sequence from A to Z, repeated n times.
    """
    return (chr(65 + (i % 26)) for i in range(n))

# Usage example:
# print(list(a_to_z_sequence(52)))  # ['A', 'B', 'C', ..., 'Y', 'Z', 'A', 'B', ...]