• <i id='llimA'><tr id='llimA'><dt id='llimA'><q id='llimA'><span id='llimA'><b id='llimA'><form id='llimA'><ins id='llimA'></ins><ul id='llimA'></ul><sub id='llimA'></sub></form><legend id='llimA'></legend><bdo id='llimA'><pre id='llimA'><center id='llimA'></center></pre></bdo></b><th id='llimA'></th></span></q></dt></tr></i><div id='llimA'><tfoot id='llimA'></tfoot><dl id='llimA'><fieldset id='llimA'></fieldset></dl></div>

  • <small id='llimA'></small><noframes id='llimA'>

    <tfoot id='llimA'></tfoot>
      <legend id='llimA'><style id='llimA'><dir id='llimA'><q id='llimA'></q></dir></style></legend>
          <bdo id='llimA'></bdo><ul id='llimA'></ul>

        如何仅将列表中每个字符串的标题大写?

        时间:2023-10-09
          <legend id='hyVrZ'><style id='hyVrZ'><dir id='hyVrZ'><q id='hyVrZ'></q></dir></style></legend>

          • <small id='hyVrZ'></small><noframes id='hyVrZ'>

            <i id='hyVrZ'><tr id='hyVrZ'><dt id='hyVrZ'><q id='hyVrZ'><span id='hyVrZ'><b id='hyVrZ'><form id='hyVrZ'><ins id='hyVrZ'></ins><ul id='hyVrZ'></ul><sub id='hyVrZ'></sub></form><legend id='hyVrZ'></legend><bdo id='hyVrZ'><pre id='hyVrZ'><center id='hyVrZ'></center></pre></bdo></b><th id='hyVrZ'></th></span></q></dt></tr></i><div id='hyVrZ'><tfoot id='hyVrZ'></tfoot><dl id='hyVrZ'><fieldset id='hyVrZ'></fieldset></dl></div>
              • <bdo id='hyVrZ'></bdo><ul id='hyVrZ'></ul>
                <tfoot id='hyVrZ'></tfoot>
                  <tbody id='hyVrZ'></tbody>

                  本文介绍了如何仅将列表中每个字符串的标题大写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  全部问题:编写一个函数,将字符串列表作为参数,并返回一个列表,其中包含每个大写为标题的字符串.也就是说,如果输入参数是 ["apple pie", "brownies","chocolate","dulce de leche","eclairs"],你的函数应该返回 ["Apple馅饼"、布朗尼"、巧克力"、德莱切"、泡芙"].

                  WHOLE QUESTION: Write a function that takes as a parameter a list of strings and returns a list containing the each string capitalized as a title. That is, if the input parameter is ["apple pie", "brownies","chocolate","dulce de leche","eclairs"], your function should return ["Apple Pie", "Brownies","Chocolate","Dulce De Leche","Eclairs"].

                  我的程序(更新):

                  我想我的程序现在正在运行!问题是当我输入: ["apple pie"] 它正在返回: ['"Apple Pie"']

                  I THINK I GOT MY PROGRAM RUNNING NOW! The problem is when I enter: ["apple pie"] it is returning: ['"Apple Pie"']

                  def Strings():
                    s = []
                    strings = input("Please enter a list of strings: ").title()
                    List = strings.replace('"','').replace('[','').replace(']','').split(",")
                    List = List + s
                  
                    return List
                  
                  def Capitalize(parameter):
                    r = []
                    for i in parameter:
                      r.append(i)
                  
                    return r
                  
                  def main():
                    y = Strings()
                    x = Capitalize(y)
                    print(x)
                  
                  main()
                  

                  我收到一个错误 AttributeError: 'list' object has no attribute 'title'请帮忙!

                  I am getting an error AttributeError: 'list' object has no attribute 'title' Please help!

                  推荐答案

                  只需遍历名称列表,然后对于每个名称,仅通过指定首字母的索引号来更改首字母的大小写.然后将返回的结果与剩余的字符相加,最后将新名称附加到已经创建的空列表中.

                  Just iterate over the name list and then for each name, change the case of first letter only by specifying the index number of first letter. And then add the returned result with the remaining chars then finally append the new name to the already created empty list.

                  def Strings():
                  
                    strings = input("Please enter a list of strings: ")
                    List = strings.replace('"','').replace('[','').replace(']','').split(",")
                  
                  
                    return List
                  
                  def Capitalize(parameter):
                    r = []
                    for i in parameter:
                      m = ""
                      for j in i.split():
                        m += j[0].upper() + j[1:] + " "
                      r.append(m.rstrip())  
                  
                  
                    return r
                  
                  def main():
                    y = Strings()
                    x = Capitalize(y)
                    print(x)
                  
                  main()
                  

                  import re
                  strings = input("Please enter a list of strings: ")
                  List = [re.sub(r'^[A-Za-z]|(?<=s)[A-Za-z]', lambda m: m.group().upper(), name) for name in strings.replace('"','').replace('[','').replace(']','').split(",")]
                  print(List)
                  

                  这篇关于如何仅将列表中每个字符串的标题大写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:格式化多维数组 Python 下一篇:仅使用字符串 format() 方法的 Python 格式日期

                  相关文章

                  最新文章

                  <legend id='NLQho'><style id='NLQho'><dir id='NLQho'><q id='NLQho'></q></dir></style></legend>

                  <small id='NLQho'></small><noframes id='NLQho'>

                  <tfoot id='NLQho'></tfoot>

                    <bdo id='NLQho'></bdo><ul id='NLQho'></ul>

                    1. <i id='NLQho'><tr id='NLQho'><dt id='NLQho'><q id='NLQho'><span id='NLQho'><b id='NLQho'><form id='NLQho'><ins id='NLQho'></ins><ul id='NLQho'></ul><sub id='NLQho'></sub></form><legend id='NLQho'></legend><bdo id='NLQho'><pre id='NLQho'><center id='NLQho'></center></pre></bdo></b><th id='NLQho'></th></span></q></dt></tr></i><div id='NLQho'><tfoot id='NLQho'></tfoot><dl id='NLQho'><fieldset id='NLQho'></fieldset></dl></div>