title: How to process each word in a python program
body: <p>I want to write a program that reads every word from every line of a text file.
  I tried using nested loop but the second loop starts reading each word. Can someone explain this? Accodrding to me it should read the individual words instead of letters.</p>
  
  <pre><code>fh=open("romeo.txt")
  d=dict()
  c=0
  for i in fh:
      for j in i:
          d[c]=j
          c+=1
  print(d)
  for i in d:
      print(d.get('moon',None))
  </code></pre>
  
  <p>the output is shown in <a href="https://i.stack.imgur.com/Qz2W2.png" rel="nofollow noreferrer">Picture 1</a></p>
  
  <p>I made a code which does the thing I want but is there any short way to do it?</p>
  
  <pre><code>fh=open("romeo.txt")
  d=dict()
  c=0
  for i in fh:
      i=i.rstrip()
      print("by the first loop ######################", i)
      k=i.split()
      for j in k:
          print("by the second loop @@@@@@@@@@@@@@@@@@", j)
          d[c]=j
          c+=1
  print(d)
  </code></pre>
  
  <p>the output which I want is given in <a href="https://i.stack.imgur.com/PYA9t.png" rel="nofollow noreferrer">Picture 2</a></p>
  
  <p>Also, can I use split() function here to do it?
  How can I use it because it seems to get only the last line of the file as a list and I want all the words in list or dictionary.</p>
  
  <p>Thank You</p>