我希望用Python编写一段代码,从txt中读取每一行,同时从该句子中获取每个数字并将其存储在一个数组中。同时,获取该新单词并将其存储在另一个数组中。
我一直在尝试排列以下代码:
while True:
content=file.readline()
print (re.sub(pattern, '', content.file.readline())
没有成功(是的,我没有指定数组!但是如果这个循环不起作用,将内容附加到数组有什么意义?)
while True:
content=file.readline()
numbah = ''
for (i,c) in enumerate(content):
if c in {'1','2','3',..}:
numbah += c)
content = content[:i-1]+content[i+1:]
print(numbah)
print(content)
还没有测试过,但尝试一下这样的 mb ?