题解 | #查找兄弟单词#
查找兄弟单词
http://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68
使用 collections.Counter 模块可以计算出字符中每个字母出现的次数。
from collections import Counter
s = input().split()
k = int(s.pop())
x = s.pop()
words = s[1:]
target_words = []
cx = Counter(x)
for word in words:
if word == x:
continue
if Counter(word) == cx:
target_words.append(word)
target_words.sort()
length = len(target_words)
print(length)
if length >= k:
print(target_words[k-1])