我有一个字符串列表的列表,例如:
example = [["string 1", "a\r\ntest string:"],["string 1", "test 2: another\r\ntest string"]]
我将使用列表推导式来替换所有字符串中的"\r\n"为一个空格,并去掉结尾处的":"符号。
对于普通列表,我会使用列表推导式来处理需要剥离或替换的项,例如:
example = [x.replace('\r\n','') for x in example]
甚至是一个lambda函数
map(lambda x: str.replace(x, '\r\n', ''),example)
但我无法使其适用于嵌套列表。有什么建议吗?