import re
text = """subject name="Biology" value="12th"
topic name="system" value="anything"
topic
subject name="mathematics" value="12th"
topic name="system" value="anything"
other topics ="anything" value="anything"
topic
subject name="chem102" value="12th"
topic name="system" value="anything"
topic
subject name="ComputerSc" value="12th"
topic name="system" value="anything"
other topics ="anything" value="anything"
topic"""

l=['Biology','chem102']
remove_topic = False

for line in text.splitlines():
	if line.startswith("subject"):
		name = re.search(r'\bname="([^"]*)"', line)
		if name:
			if name.group(1) in l:
				remove_topic = True
		print(line)
	elif line.strip() == "topic" and remove_topic:
		print()
		remove_topic = False
	else:
		print(line)