title: Print one word from a list within a dictionary (python)
body: <p>I want my program to print only one random word from the list within my dictionary, but I can't seem to get the right syntax to do so. I attempted using popitem() to get a random value from the list, but it doesn't seem to be working. Here is my code: </p>
  
  <pre><code>import random
  
  thesaurus = {
                "happy":["glad",  "blissful", "ecstatic", "at ease"],
                "sad"  :["bleak", "blue", "depressed"]
              }
  
  # input
  phrase = input("Enter a phrase: ")
  
  # turn input into list
  part1 = phrase.split()
  part2 = list(part1)
  
  newlist = [] 
  for x in part2:
      s = thesaurus.get(x, x)
      newlist.append(s)
  
  print (newlist)
  </code></pre>
  
  <p>For example, if the input is</p>
  
  <pre><code>i am happy
  </code></pre>
  
  <p>The expected output would be </p>
  
  <pre><code>i am glad
  </code></pre>
  
  <p>or any random word from the list within the dictionary.</p>
  
  <p>But, right now my output looks like this: </p>
  
  <pre><code>['i', 'am', ['glad', 'blissful', 'ecstatic', 'at ease']]
  </code></pre>
  
  <p>I know there is another thread involved with this, but it doesn't seem to address this specific issue.</p>
  
  <p>Any help would be appreciated! </p>
  
  <p>edit: </p>
  
  <p>If I extended this formula to work with an imported file with a long list of words, how would I have to change the code?</p>
  
  <pre><code>newDict = {}
  with open('thesaurus.txt', 'r') as f:
      for line in f:
          splitLine = line.split()
          newDict[(splitLine[0])] = ",".join(splitLine[1:])
  
  print ("Total words in thesaurus: ", len(newDict))
  
  # input
  phrase = input("Enter a phrase: ")
  
  # turn input into list
  part1 = phrase.split()
  part2 = list(part1)
  
  # testing input
  newlist = []
  for x in part2:
      s = newDict[x].pop() if x in newDict else x
      s = random.choice(newDict[x]).upper() if x in newDict else x
      newlist.append(s)
  
  
  newphrase = ' '.join(newlist)
  print (newphrase)
  </code></pre>
  
  <p>sample of line text within the "thesaurus" file: </p>
  
  <pre><code>abash,humility,fear
  </code></pre>