Skip to content

Code Performance Optimization and Request for Code Review #1

Description

@OfficialAhmed

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions