>>> match = re.findall(r'\w\w', 'hello')
>>> print match
['he', 'll']
Run Code Online (Sandbox Code Playgroud)
因为\ w\w意味着两个字符,'他'和'll'是预期的.但为什么'el'和'lo' 与正则表达式不匹配?
>>> match1 = re.findall(r'el', 'hello')
>>> print match1
['el']
>>>
Run Code Online (Sandbox Code Playgroud) 假设我有一个清单 A
A = [1,2,3,4,5,6,7,8,9,10]
Run Code Online (Sandbox Code Playgroud)
我想B按以下顺序使用上述列表创建一个新列表(例如)。
B = [[1,2,3], [3,4,5], [5,6,7], [7,8,9], [9,10,]]
Run Code Online (Sandbox Code Playgroud)
即前三个数字为A[0,1,2],后三个数字为A[2,3,4],依此类推。
我相信其中有一种numpy用于此类操作的功能。