How do I iterate through the alphabet?

MillsOnWheels picture MillsOnWheels · Jun 19, 2013 · Viewed 87.6k times · Source

In Python, could I simply ++ a char? What is an efficient way of doing this?

I want to iterate through URLs that have the www.website.com/term/#, www.website.com/term/a, www.website.com/term/b, www.website.com/term/c, www.website.com/term/d ... www.website.com/term/z format.

Answer

Jared picture Jared · Jun 19, 2013

You can use string.ascii_lowercase which is simply a convenience string of lowercase letters,

>>> from string import ascii_lowercase
>>> for c in ascii_lowercase:
...     # append to your url