I have 2 dictionaries : group1 and group2 and I need to replace the line will null/delete for line in text file if in dictionary: {'car': set(['ab', 'ef', 'ad', 'cd']), 'bike': set(['ac', 'de'])} {'car': ['go', 'drive', 'enjoy'], 'bike': ['ride']} My file: !hello!! mycar car(ab,ef,ad,cd) go drive enjoy bike(ac,de) ride Expected output !hello!! mycar The output has to be written to the same file without affecting/other lines and its indentations! Continue reading...