If you want no repetitions:
import string, random
''.join(random.sample(string.ascii_lowercase, X))
If you DO want (potential) repetitions:
import string, random
''.join(random.choice(string.ascii_lowercase) for _ in xrange(X)))
That's assuming that by a-z
you mean "ASCII lowercase characters", otherwise your alphabet might be expressed differently in these expression (e.g., string.lowercase
for "locale dependent lowercase letters" that may include accented or otherwise decorated lowercase letters depending on your current locale).