在字符串中查找最短名称在cod中识别问题

2024-03-28 11:40:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要在学生名单中找出最短的名字。你知道吗

到目前为止,我已经输入了以下代码,但它没有给我任何输出。你知道吗

有人能帮我找出代码的问题吗?你知道吗

students = ["a bunch of student names I will not show"]
students.sort(key=len)
shortest_name = (students[0])
print ("The shortest name is ,", shortest_name)

非常感谢!你知道吗


Tags: ofkey代码namenamesshownot名字
1条回答
网友
1楼 · 发布于 2024-03-28 11:40:11

正如您在string (not list of strings)中询问的最短名称。变更最小的工作代码为:

students = "a bunch of student names I will not show"
students = sorted(students.split(), key=len)
shortest_name = students[0]
print("The shortest name is ,", shortest_name)

相关问题 更多 >