Use os.path.splitext instead of ends with