Instead of generating a list of lowercase letters for checking a better implementation is the islower() method. You may get rid of the following block of code to a simple one line
lowercase_characters = [chr(ele) for ele in range(97, 97 + 26)]
for char in word:
if char not in lowercase_characters:
return "Only lowercase letters are allowed"
# islower() checks the entire string if all char(s) lower case
if not islower(text_to_check):
return "Only lowercase letters are allowed"
Eliminating the for-loop reduces the steps executed, hence faster code execution
Eliminating the list comprehension and checking reduces steps executed, hence faster code execution
Not to mention the code is more user-friendly and easy to read
Instead of generating a list of lowercase letters for checking a better implementation is the
islower()method. You may get rid of the following block of code to a simple one lineEliminating the
for-loopreduces the steps executed, hence faster code executionEliminating the
list comprehensionand checking reduces steps executed, hence faster code executionNot to mention the code is more user-friendly and easy to read