f=open("oppijavastavused.txt", "r") r=f.readlines() f.close() for rida in r: koht=rida.find("] [") rida=rida[:koht+1].replace("[", ",").replace("]", "") print rida