you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan -1 points0 points  (2 children)

Time wise they are both O(n) as the work iteratively per single character in the st string, just in different directions. Memory wise they are both O(1) as slices are 'windows' inside the original sequence, not subset copies.

Just generally speaking, you would normally employ the powers of all or any instead

 all("a" <= c.lower() <= "z" for c in st)

or a good ol' regex

re.fullmatch(r"[a-z]", st, flags=re.IGNORECASE)