Answer the question
In order to leave comments, you need to log in
How to iterate over one word in each line?
elif '<math-input-answer>' in answer_row['content']:
correct= answer_row['content'].partition('<math-input-answer>')[2].partition('</math-input-answer>')[0]
print(correct)
<p><vim-math id="m7859635math1">AB+CD=|</vim-math><math-input id="m7859635MI1" keyboard-skin="junior" keyboard-type="base" strict-check="false">
<math-input-answer>x+y</math-input-answer>
<math-input-answer>y+x</math-input-answer>
</math-input><vim-math id="m7859635math2">|+|</vim-math><math-input id="m7859635MI2" keyboard-skin="junior" keyboard-type="base" strict-check="false">
<math-input-answer>t+z</math-input-answer>
<math-input-answer>z+t</math-input-answer>
Answer the question
In order to leave comments, you need to log in
data = '''<p><vim-math id="m7859635math1">AB+CD=|</vim-math><math-input id="m7859635MI1" keyboard-skin="junior" keyboard-type="base" strict-check="false">
<math-input-answer>x+y</math-input-answer>
<math-input-answer>y+x</math-input-answer>
</math-input><vim-math id="m7859635math2">|+|</vim-math><math-input id="m7859635MI2" keyboard-skin="junior" keyboard-type="base" strict-check="false">
<math-input-answer>t+z</math-input-answer>
<math-input-answer>z+t</math-input-answer>'''
string = '<math-input-answer>'
results =[]
def get_text(line):
line = line.split('>')[1]
line = line.split('<')[0]
return line
for line in data.splitlines():
if string in line:
result = get_text(line)
results.append(result)
print(results)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question