问题:编写一个函数,它将一个字符串列表作为参数,并返回一个包含大写为标题的每个字符串的列表。也就是说,如果输入参数是["apple pie","brownies","dulce de leche"]
,则您的函数应返回["Apple Pie","Brownies","Dulce De Leche"]
。如何大写列表中每个字符串的标题?
我写了这个程序。问题是如果我输入["apple pie", "brownies","dulce de leche"]
,则返回['Apple Pie', ' Brownies', 'Dulce De Leche']
如问题所示,每个字符串都必须用逗号打印出来,并且在逗号后面没有空格。 请帮助!
这里是我的程序:
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()
这是一个DUP:http://stackoverflow.com/questions/29463718/how-to-capitalize-only-the-title -of-each-string-in-the-list – dbliss 2015-04-06 02:36:13