shorter in python – checking duplicate characters