title: Python 2.7 finding if some anagram of one string is a substring of another
body: <p>EDIT: Posting my final solution because this was a very helpful thread and I want to add some finality to it. Using the advice from both answers below I was able to craft a solution. I added a helper function in which I defined an anagram. Here is my final solution:</p>
  
  <pre><code>def anagram(s1, s2):
      s1 = list(s1)
      s2 = list(s2)
      s1.sort()
      s2.sort()
      return s1 == s2
  
  def Question1(t, s):
      t_len = len(t)
      s_len = len(s)
      t_sort = sorted(t)
      for start in range(s_len - t_len + 1):
          if anagram(s[start: start+t_len], t):
              return True
      return False
  
  print Question1("app", "paple")
  </code></pre>
  
  <hr>
  
  <p>I am working on some practice technical interview questions and I'm stuck on the following question:</p>
  
  <p><code>Find whether an anagram of string t is a substring of s</code></p>
  
  <p>I have worked out the following two variants of my code, and a solution to this I believe lies in a cross between the two. The problem I am having is that the first code always prints <code>False.</code>, regardless of input. The second variation works to some degree.  However, it cannot sort individual letters. For example <code>t=jks s=jksd</code> will print <code>True!</code> however <code>t=kjs s=jksd</code> will print <code>False.</code></p>
  
  <pre><code>def Question1():
      # Define strings as raw user input.
      t = raw_input("Enter phrase t:")
      s = raw_input("Enter phrase s:")
      # Use the sorted function to find if t in s
      if sorted(t.lower()) in sorted(s.lower()):
          print("True!")
      else:
          print("False.")
  
  Question1()
  </code></pre>
  
  <p>Working variant:</p>
  
  <pre><code>def Question1():
      # Define strings as raw user input.
      t = raw_input("Enter phrase t:")
      s = raw_input("Enter phrase s:")
      # use a loop to find if t is in s.
      if t.lower() in s.lower():
          print("True!")
      else:
          print("False.")
  
  Question1()
  </code></pre>
  
  <p>I believe there is a solution that lies between these two, but I'm having trouble figuring out how to use <code>sorted</code> in this situation.</p>