标签:str app pop sof als key dict cep form
"""
输入一串字符,检查是否可以组成friend
"""
from collections import Counter
def foo(num_list):
for i in friend:
try:
num = count[i]
if num < num_list[0]:
num_list.pop()
num_list.append(num)
except KeyError as e:
print(‘输入的字符串不能组成friend。。。‘)
return False
return num_list
my_str = input(‘随意输入一串字符:‘)
count = dict(Counter(my_str))
friend = ‘friend‘
num_list = [len(my_str)]
if foo(num_list):
print(‘可以组成 {} 个friend!‘.format(num_list))
标签:str app pop sof als key dict cep form
原文地址:https://www.cnblogs.com/changqing8023/p/9068465.html