title: How to sort a list of words by length
body: <p>I want to sort words in a list based on length.</p>
  
  <p>The test case is <code>{'cat','jump','blue','balloon'}</code></p>
  
  <p>When run through this method it will print something along the lines of:</p>
  
  <pre><code>{'balloon','jump','blue','balloon'}
  </code></pre>
  
  <p>Another problem I have run into, is that the type of python we were using worked fine, however when I try to run the .py in the Python 3.5.2 shell, it comes up with errors.</p>
  
  <p>I mainly just need to know what I did wrong, and what I can do to fix it so that it works. Any help is appreciated!</p>
  
  <p>The .py file can be found <a href="https://drive.google.com/file/d/0B6qZYcl-qhFmQVBUSmxKUmx3eE0/view?usp=sharing" rel="nofollow noreferrer">here:</a></p>
  
  <pre><code>def wordSort():
      words = []
      minimum = 'NaN'
      index = 0
      x = 0    
      y = 0    
      z = 1
      #How many words to be entered
      length = input('How many words would you like to enter? ')
      #Put words in the number of times you entered previously    
      while not z &gt;= length + 1:
          words.append(raw_input('Enter word #' + str(z) + ': '))
          z += 1
      while x &lt; length:
          minimum = words[x]
          #Goes through the list and finds a smaller word
          while y &lt; length:
              if len(words[y]) &lt; len(minimum):
                  minimum = words[y]
                  index = y
              y += 1
          words[index] = words[x]
          words[x] = minimum
          x += 1
      print words
  </code></pre>