[Python] Python deleting line or replacing line with null for a line in dictionary

Discussão em 'Python' iniciado por Stack, Junho 14, 2025.

  1. Stack

    Stack Membro Participativo

    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...

Compartilhe esta Página