我有一个如下所示的字符串:
[Base Font : IOHLGA+Trebuchet, Font Size : 3.5324998, Font Weight : 0.0] [(X=250.44,Y=223.48499) height=3.5324998 width=4.2910004]DECEMBER 31,
[Base Font : IOFOEO+Imago-Book, Font Size : 3.876, Font Weight : 0.0] [(X=307.5,Y=240.48499) height=3.876 width=2.9970093]respectively. The net decrease in the revenue
[Base Font : IOHLGA+Trebuchet, Font Size : 3.5324998, Font Weight : 0.0] [(X=49.5,Y=233.98499) height=3.5324998 width=2.5690002](US$ in millions)
我想提取“X”的值和关联的文本并将其转换为列表。请参阅下面的预期输出:
预期输出:
['X=250.44','DECEMBER 31,']
['X=307.5','respectively. The net decrease in the revenue']
['X=49.5','(US$ in millions)']
我们如何在 Python 中解决这个问题?
我的方法:
mylist = []
for line in data.split("\n"):
if line.strip():
x_coord = re.findall('^(X=.*)\,$', line)
text = re.findall('^(]\w +)', line)
mylist.append([x_coord, text])
我的方法没有发现x_coord和的任何价值text。
郎朗坤
斯蒂芬大帝
MYYA
相关分类