def counts(wrd, q): '''统计字频''' for x1 in wrd: q[x1] += 1 return q for line in sys.stdin: _, *words, wd, k = line.strip().split(" ") a1 = counts(wd, dict.fromkeys(wd, 0)) # 查找词的字频统计 l = [] for w in words: a2 = counts(w, dict.fromkeys(w, 0)) # 被查找词的字频统计 if wd != w and a1 == a2: # 符合兄弟词的条件 l.append(w) ...