How to iterate through the alphabet?

python, python-2.7, python-3.x

Solution

You can try this:

import string

letters = list(string.ascii_lowercase)

letters.extend([i+b for i in letters for b in letters])

print letters

By using a double for loop, we iterate over the alphabet like we normally would, except we can put the iteration in list comprehension, to save space and be more pythonic.

Problem

How can I iterate through the alphabet and have it continue past the letter Z? For example - a,b,c ... y,x,aa,ab,ac,ad At the momenent this is my array ``` letters = [ "a","b","c","d","e","f","g","h","i","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", "bi", "bj", "bk", "bl", "bm", "bn", "bo", "bp", "bq", "br", "bs", "bt", "bu", "bv","bw", "bx", "by", "bz","ca","cb","cc","cd","ce", "cf","cg","ch","ci","cj","ck","cl","cm","cn","co","cp", "cq","cr","cs","ct","cu","cv","cw"] ``` but I want to make it created within a loop.

Original source

Related problems