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'?