import re f=open("nonosis.txt") f2=open("nonoval.txt", "w") f.readline() m=[rida.strip() for rida in f.readlines()] for rida in m: print(" ".join([str(len(plokk)) for plokk in re.findall("(#+)", rida)]), file=f2) for rida in list(zip(*m)): print(" ".join([str(len(plokk)) for plokk in re.findall("(#+)", "".join(rida))]), file=f2) #print(list(zip(*m))) f2.close()