|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
def dif(str):
a = list(str[0])
for each in str:
if not (each in a):
a.append(each)
return a
def count(str):
#a =['%', '$', '@', '_', '^', '#', ')', '&', '!', '+', ']', '*', '}', '[', '(', '{', '\n', 'G', 'O', 'D', 'L', 'U', 'C', 'K']
a = dif(str)
l = len(a)
y = 0
hua = []
for n in range(l):
for m in str:
if a[n] == m:
y+=1
print(m)
if a[n] =='\n':
print('\\n'+' 出现的次数%d' % y)
print('............')
else:
print(a[n]+' 出现的次数为%d' % y)
if y<=2:
hua.append(a[n])
y = 0
print(hua)
查找符号出现的次数
ist1 = []
for each in str1:
if each not in list1:
if each == '\n':
print('\\n', str1.count(each))
else:
print(each, str1.count(each))
list1.append(each)
注意count()的使用
|
|