在列表中标准化名称(Python)

2024-10-03 15:28:35 发布

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

我需要将列表中的名字规范化。例如: (巴西名字)

这位是伊戈尔·达席尔瓦 应该是这样的:伊戈尔·达席尔瓦

-每个名字的第一个字母都应该大写,但只有第一个字母。 -连词,如“da”只能用小写字母书写 -所有多余的空间都必须去掉

有人知道怎么做吗?在


Tags: 列表字母空间名字规范化da书写大写
1条回答
网友
1楼 · 发布于 2024-10-03 15:28:35

The first letter of every name should be capitalized, but only the first letter.

查看string.title()方法

-The conecting words, such as "da" should be written in only lowercase

查看string.lower()方法

-All the extra spaces must be removed

研究string.split()方法来分隔名称,使用" ".join()方法用一个空格重新组合它们。在

相关问题 更多 >