Swap last index access with str.endswith()