title: Python: How to properly use readline() and readlines()
body: <p>I've build a Python script to randomly create sentences using data from the Princeton English Wordnet, following diagrams provided by <a href="http://godel-escher-bach.wikia.com/wiki/Chapter_5" rel="nofollow noreferrer">Gödel, Escher, Bach</a>. Calling <code>python GEB.py</code> produces a list of nonsensical sentences in English, such as:</p>
  
  <p>resurgent inaesthetic cost.
  the bryophytic fingernail.
  aversive fortieth peach.
  the asterismal hide.
  the flour who translate gown which take_a_dare a punch through applewood whom the renewed request enfeoff.
  an lobeliaceous freighter beside tuna.</p>
  
  <p>And saves them to gibberish.txt. This script works fine.</p>
  
  <p>Another script (<code>translator.py</code>) takes gibberish.txt and, through py-googletrans Python module, tries to translate those random sentences to Portuguese:</p>
  
  <pre><code>from googletrans import Translator
  import json
  
  tradutor = Translator()
  
  with open('data.json') as dataFile:
      data = json.load(dataFile)
  
  
  def buscaLocal(keyword):
      if keyword in data:
          print(keyword + data[keyword])
      else:
          buscaAPI(keyword)
  
  
  def buscaAPI(keyword):
      result = tradutor.translate(keyword, dest="pt")
      data.update({keyword: result.text})
  
      with open('data.json', 'w') as fp:
          json.dump(data, fp)
  
      print(keyword + result.text)
  
  
  keyword = open('/home/user/gibberish.txt', 'r').readline()
  buscaLocal(keyword)
  </code></pre>
  
  <p>Currently the second script outputs only the translation of the first sentence in gibberish.txt. Something like:</p>
  
  <p>resurgent inaesthetic cost.
  aumento de custos inestético.</p>
  
  <p>I have tried to use <code>readlines()</code> instead of <code>readline()</code>, but I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "main.py", line 28, in &lt;module&gt;
      buscaLocal(keyword)
    File "main.py", line 11, in buscaLocal
      if keyword in data:
  TypeError: unhashable type: 'list'
  </code></pre>
  
  <p>I've read similar questions about this error here, but it is not clear to me what should I use in order to read the whole list of sentences contained in gibberish.txt (new sentences begin in a new line).</p>
  
  <p>How can I read the whole list of sentences contained in gibberish.txt? How should I adapt the code in <code>translator.py</code> in order to achieve that? I am sorry if the question is a bit confuse, I can edit if necessary, I am a Python newbie and I would appreciate if someone could help me out.</p>