path='sun.txt' sun_txt=open(path,'r') dic1={} count=0 text=sun_txt.readlines() a1="" for i in text : s=i.split() for new in s : if new=='/': count+=1 if count==3 : dic1[a1]+=1 else: a1=a1+new print(dic1)