整个问题:编写一个函数,它将一个字符串列表作为参数,并返回一个列表,其中包含大写为标题的每个字符串。也就是说,如果输入参数是["apple pie", "brownies","chocolate","dulce de leche","eclairs"]
,那么你的函数应该返回["Apple Pie", "Brownies","Chocolate","Dulce De Leche","Eclairs"]
。如何只大写列表中每个字符串的标题?
我的计划(修订版):
我想我得到了我的程序运行NOW!问题是,当我输入:["apple pie"]
它返回:['"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'
请帮帮忙!
你给我们您正在试图解决的问题的说明,所以,什么是你的问题? – belwood 2015-04-06 00:14:22
如何将列表中每个字符串的标题大写? – brilliant 2015-04-06 00:15:14