path='sw.txt' sample_txt=open(path,'r') dic={} text=sample_txt.readlines() for i in text : if i not in dic : dic[i]=1 else : dic[i]+=1 print(dic)