#取出字符串中出现2次的字符串,使用count方法统计def two_zifuchuan(str): s=set() for i in str: if str.count(i)==2: s.add(i) return s #取出字符串中出现2次的字符串,使用字典统计 def two_occur(str): s={} for i in str: if i in s.keys(): s[i]+=1 else: s[i]=1 return [i for i in s if s[i]==2] str="dddredddddewws22dff43" print(two_zifuchuan(str)) print(two_occur(str))
原文地址:https://www.cnblogs.com/xiaokuangnvhai/p/11465194.html
时间: 2024-10-07 22:15:41