title: python given query string find a set of strings with same beginning
body: <p>Edit: I appreciate all the answers but could anyone tell me why my solution is not working? I wanted to try to do this without the .startswith() thank you!</p>
  <p>I am trying to complete this excercise:</p>
  <blockquote>
  <p>Implement an autocomplete system. That is, given a query string and a set of all possible query strings,
  return all strings in the set that have s as a prefix.
  For example, given the query string de and the set of strings [dog, deer, deal], return [deer, deal].
  Hint: Try preprocessing the dictionary into a more efficient data structure to speed up queries.</p>
  </blockquote>
  <p>But I get a empty list. What could I be doing wrong? I thought this would give me [deer, deal]</p>
  <pre><code>def autocomplete(string,set):
      string_letters = []
      letter_counter = 0
      list_to_return = []
  
      for letter in string:
          string_letters.append(letter)
  
      for words in set:
          for letter in words:
              if letter_counter == len(string):
                  list_to_return.append(words)
              if letter == string_letters[letter_counter]:
                  letter_counter += 1
              else:
                  break
      return list_to_return
  
  print(autocomplete(&quot;de&quot;, [&quot;dog&quot;,&quot;deer&quot;,&quot;deal&quot;]))
  </code></pre>
  <p>output:</p>
  <pre><code>[]
  
  </code></pre>
  <p>Edit: I appreciate all the answers but could anyone tell me why my solution is not working? I wanted to try to do this without the .startswith() thank you!</p>