且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从字符串列表的元素中删除结尾的换行符

更新时间:2023-02-09 13:00:33

>>> my_list = ['this\n', 'is\n', 'a\n', 'list\n', 'of\n', 'words\n']
>>> map(str.strip, my_list)
['this', 'is', 'a', 'list', 'of', 'words']