题解 | #查找兄弟单词#

查找兄弟单词

https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68

lst = input().strip().split(' ') #得到输入字符串以空格分开的列表
words = lst[1:int(lst[0])+1] #得到要处理的单词列表
index = int(lst[-1]) #得到目标索引
target = lst[-2] #得到目标单词
brothers = [] #构建兄弟单词空列表
for word in words: #遍历单词列表
    if target != word and sorted(target) == sorted(word): #如果符合兄弟单词特征就加入兄弟单词列表
        brothers.append(word)
brothers.sort() #对兄弟单词列表进行排序
print(len(brothers)) #输出符合单词列表的个数
try:
    print(brothers[index-1]) #尝试输出单词列表的目标索引单词
except:
    pass

全部评论

相关推荐

05-19 19:57
蚌埠学院 Python
2237:Gpa70不算高,建议只写排名,个人技能不在多而在精,缩到8条以内。项目留一个含金量高的,减少间距弄到一页,硕士简历也就一页,本科不要写很多
实习,投递多份简历没人回...
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务