How to check if a string is a valid identifier in python?