我有50个值,看起来像这样的列表:我可以使用Python格式化列表中的文本吗?
['xxxxxx\n', 'xxxxxx\n', 'xxxxxx\n', 'xxxxxx\n', 'xxxxxx \n', 'xxxxxx\n',
' xxxxxx \n', 'xxxxxx \n', 'xxxxxx\n', ...]
我想打印的清单作为一个名单,但格式化列表中的文本。我想删除该单词前后的空格(在此示例中用xxxxxx替换)以及使用.title()
函数。
我已经试过这样做,但我得到的错误:
AttributeError: 'list' object has no attribute 'strip'
我的理解是错误的,但我不知道是否有任何其他的方式来格式化文本列表内。
延伸阅读:http://docs.python.org/tutorial/ datastructures.html#列表理解 – cheeken 2012-02-21 00:43:17
这是完美的!非常感谢:) – emagdnim 2012-02-21 00:47:22