4
我有如下字符串列表:掌握新行字符
s = 'hello\n this is\n a forum\n'
,我使用正则表达式来获取每个字符的每个单人/双人发生。我想生成作为li = [ 'h','e','ll','o','\n','t','h'....]
我用
pattern = re.compile(r'(.)\1?' , re.IGNORECASE)
newList = [m.group() for m in pattern.finditer(s)]
print newList
但是,这给了我newList= [ 'h','e','ll','o','t','h'....]
,在这里我无法得到的“\ n”新行存储的字符的列表。我应该如何改变我的模式以获得列表中的'\ n'?