如何将名称列表转换为缩写
我有一个只需转向缩写的名称列表,因此['姓氏,名称']将为ns。这是我到目前为止所做的:
list_names = [['Johnson, Sarah'],['Hill, Becky'],['Smith, John']]
for name in list_names:
for name_string in name:
split = name_string.split(", ")
join = " ".join(split)
initials = ""
for n in split:
initials += n[0].upper()
print(initials)
我认为这是我出错的最后一步,任何帮助都非常感谢
:我现在已经修复了错字,名称最初是在numpy.ndarray中。进入名为list_names的列表
I have a list of names that I need to turn to initials only, so for example ['Surname, Name'] would be NS. This is what I have done so far:
list_names = [['Johnson, Sarah'],['Hill, Becky'],['Smith, John']]
for name in list_names:
for name_string in name:
split = name_string.split(", ")
join = " ".join(split)
initials = ""
for n in split:
initials += n[0].upper()
print(initials)
I think it's one of the last steps where I'm going wrong, any help is much appreciated
Edit: I have fixed the typo now, the names were originally in numpy.ndarray which I then turned into the list called list_names
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了拆分,我已经使用了.split(“”,“,”)逗号加上空间,就像输入列表中一样。
我认为您希望以这种方式输出:
For splitting i have used .split(", ") comma plus space as is it included in the input list.
I think you want output in this way:
您可以通过列表理解
结果来完成:
You can do it with a list comprehension
result: