我有 list :
mylist = ["all dogs go", "why does one", "fell down so hard I"]
是否有一个函数可以让我在 mylist 中的每个元素的末尾添加单词 “moo”?
请您参考如下方法:
使用列表理解:
>>> mylist[:] = [word.strip() + " moo" for word in mylist]
>>> print mylist
['all dogs go moo', 'why does one moo', 'fell down so hard I moo']
