fork download
  1.  
  2. s=r"""New York City; Iron Man; no superpowers
  3. Metropolis; Superman; superpowers;
  4. New York City;
  5. Spider-Man;
  6. superpowers;
  7. Gotham; Batman; no superpowers;
  8. New York City; Doctor Strange; superpowers;"""
  9. tmp = ''
  10. for line in s.splitlines():
  11. if len(line.rstrip(';').split(';')) < 3:
  12. tmp += line
  13. else:
  14. if tmp: # write fixed line to fixed file
  15. print(tmp)
  16. tmp = ''
  17. else: # write existing line to fixed file
  18. print(line)
Success #stdin #stdout 0.01s 27696KB
stdin
Standard input is empty
stdout
New York City; Iron Man; no superpowers
Metropolis; Superman; superpowers;
New York City;Spider-Man;superpowers;
New York City; Doctor Strange; superpowers;