【发布时间】:2018-03-20 10:48:41
【问题描述】:
我的字符串很长:
query = "PREFIX pht: <http://datalab.rwth-aachen.de/vocab/pht/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?Age, ?SexTypes, ?Chest_Pain_Type, ?trestbpsD, ?cholD,
?Fasting_Glucose_Level, ?Resting_ECG_Type, ?thalachD,
?Exercise_Induced_Angina, ?oldpeakD, ?caD, ?Slope, ?Thallium_Scintigraphy, ?Diagnosis
WHERE {?URI a sct:125676002. }"
现在我需要创建一个包含所有以“?”开头的子字符串的列表。所以列表应该如下所示:
schema = ['Age', 'Sex', 'Chest_Pain_Type', 'Trestbps', 'Chol', 'Fasting_Glucose_Level', 'Resting_ECG_Type', 'ThalachD',
'Exercise_Induced_Angina', 'OldpeakD', 'CaD', 'Slope', 'Thallium_Scintigraphy', 'Diagnosis']
我试过str.startswith(str, beg=0,end=len(string))
但它并没有像我预期的那样工作。如何在 Python 中做到这一点?
【问题讨论】:
-
为什么 ?URI 不在结果中?
-
vbar,不错的收获!实际上,我不需要 ?URI。我想解释一下,但后来认为这会增加问题的复杂性。
-
是的,它确实增加了复杂性...... :-) 正则表达式可以找到所有以'?'开头的单词(见下文),但如果你想根据更大的上下文跳过其中的一些,你需要更多的步骤......