求写代码。要求:1.提取列表中’ ’的内容; 2.换行;谢谢。
比如:提取图片中’暨大’
如果你给的这些数据是字符串,则使用如下代码:
import re
example = "[array(['暨大!!!!!!'],dtype=object),array(['我觉得小姐姐人很好哎'],dtype=object), array(['工科走了'], dtype=object),array(['点错了'],dtype=object),array(['机械计制造及其自动化'], dtype=object), array(['你已经很棒了呀'], dtype=object),array(['二本想考研985的瑟瑟发抖'], dtype=object), array(['我导师就这样,我都气死了'], dtype=object), array(['在读大三的一名博士研究生 关系复杂'], dtype=object), array(['音乐生在这!', dtype=object), array(['哈哈哈'], dtype=object), array(['广美硕士路过'],dtype=object),array(['内心热爱,就坚持。不热爱,完全没必要。'],dtype=object),array(['【过期的麦片】'],dtype=object), array(['一猜就是,哈哈哈'],dtype=object),array(['好的,医学生现在退出直播间'], dtype=object),array(['重新定义《普通》'], dtype=object),array(['感觉up主不太会问问题'],dtype=object), array(['顶部红字你有意思吗? '], dtype=object), array(['重点是能毕业'],dtype=object),array(['如果这样的话那我真心建议你退学'], dtype=object), array(['社会是很险恶的'],dtype=object),array(['期待第二期!'], dtype=object), array(['加油,曾经都努力了为什么要放弃呢'],dtype=object),array(['摆就完了'], dtype=object), array(['哈哈哈哈'], dtype=object),array(['说的就是我'], dtype=object),array"
print('\n'.join(re.findall(r"'(.*?)'", example)))
如果你上面的是存放 numpy.ndarray
类型元素的列表,可以转换成字符串按上述方法获取,也可以用如下方法获取:
import re
import numpy as np
example = "[array(['暨大!!!!!!'],dtype=object),array(['我觉得小姐姐人很好哎'],dtype=object), array(['工科走了'], dtype=object),array(['点错了'],dtype=object),array(['机械计制造及其自动化'], dtype=object), array(['你已经很棒了呀'], dtype=object),array(['二本想考研985的瑟瑟发抖'], dtype=object), array(['我导师就这样,我都气死了'], dtype=object), array(['在读大三的一名博士研究生 关系复杂'], dtype=object), array(['音乐生在这!', dtype=object), array(['哈哈哈'], dtype=object), array(['广美硕士路过'],dtype=object),array(['内心热爱,就坚持。不热爱,完全没必要。'],dtype=object),array(['【过期的麦片】'],dtype=object), array(['一猜就是,哈哈哈'],dtype=object),array(['好的,医学生现在退出直播间'], dtype=object),array(['重新定义《普通》'], dtype=object),array(['感觉up主不太会问问题'],dtype=object), array(['顶部红字你有意思吗? '], dtype=object), array(['重点是能毕业'],dtype=object),array(['如果这样的话那我真心建议你退学'], dtype=object), array(['社会是很险恶的'],dtype=object),array(['期待第二期!'], dtype=object), array(['加油,曾经都努力了为什么要放弃呢'],dtype=object),array(['摆就完了'], dtype=object), array(['哈哈哈哈'], dtype=object),array(['说的就是我'], dtype=object),array"
data = [np.array(string, dtype=object) for string in re.findall(r"'(.*?)'", example)]
for d in data:
print(d.item())
其中data后面请赋值存放 numpy.ndarray
类型元素的列表,我这只有字符串,所以需要经过上面处理还原成你的例子。