''' 求字符串"dfjkfjeijdkf" 计算个数为1字符及其下标 ''' def str_single(string): a={} for n,i in enumerate(string,0): if i not in a: a[i]=[n] else: a[i].append(n) result = {} for i,j in a.items(): if len(j) == 1: result[i] = j[0] return result print(str_single("adsax"))