Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中标题的适当大小写_Python - Fatal编程技术网

Python中标题的适当大小写

Python中标题的适当大小写,python,Python,我正在寻找一个库,它通过假设给定的字符串是一个标题来正确地大写它。我知道有string.title(),但它将所有作品都大写,而不仅仅是应该大写的作品。有人知道图书馆吗 标题中不应大写的单词示例: 命题(来自、来自等) 条款(a、an、the) 货车 德 谷歌的术语是“标题酶”。最重要的是: 如果要大写字符串,但仅大写某些单词,则需要在某些列表中指定不希望大写的单词,然后执行类似的操作: excluded_words = ["words","you","want","excluded"] t

我正在寻找一个库,它通过假设给定的字符串是一个标题来正确地大写它。我知道有string.title(),但它将所有作品都大写,而不仅仅是应该大写的作品。有人知道图书馆吗

标题中不应大写的单词示例:

  • 命题(来自、来自等)
  • 条款(a、an、the)
  • 货车
    • 谷歌的术语是“标题酶”。最重要的是:


      如果要大写字符串,但仅大写某些单词,则需要在某些列表中指定不希望大写的单词,然后执行类似的操作:

      excluded_words = ["words","you","want","excluded"]
      
      titled = [word.capitalize() if word not in excluded_words else word 
                 for word in title.split(" ")]
      
      只有当您有一些奇怪的(或未实现的)标准想要使用时,才可以这样做。
      如果你能找到一个能做到这一点并且符合你想要的标准的软件包,那么就用它来代替。

      如何将“驾驶一辆厢式车回家”大写?“驾驶一辆厢式车回家”用一个集合来代替:
      excluded\u words={“words”,“you”,“want”,“excluded”}
      。集合使用哈希,这是非常有效的。
      excluded_words = ["words","you","want","excluded"]
      
      titled = [word.capitalize() if word not in excluded_words else word 
                 for word in title.split(" ")]