title: Increasing Speed of Fuzzy Matching words on two lists
body: <p>I have a list of about 500 items on one list. I'd like to replace all fuzzy-matched items in that list with the smallest length item.</p>
  
  <p>Is there a way to speed up my implementation of fuzzy match?</p>
  
  <p>Note: I posted a similar question before, but I'm reframing it due to lack of response.</p>
  
  <p>My implementation:</p>
  
  <pre><code>def find_fuzzymatch_samelist(list1, list2, cutoff=90):
      """
      #list1 = list(ds1.Title)
      #list2 = list(ds1.Title)
      """
      matchdict = defaultdict(list)
  
      for i, u in enumerate(list1):
  
          for i1, u1 in enumerate(list2):
  
              #Since list orders are the same, this makes sure this isn't the same item.
              if i != i1:
  
                  if fuzz.partial_token_sort_ratio(u, u1) &gt;= cutoff:
                      pair = (u, u1)
  
                      #Because there are potential duplicates, I have to make the key constant.
                      #Otherwise, putting list1 as the key will result in both duplicate items
                      #serving as the key. 
  
                      """
                      Potential problem:
                      • what if there are diffrent shortstr? 
  
                      """
  
                      shortstr = min(pair, key=len)
                      longstr = max(pair, key=len)     
                      matchdict[shortstr].append(longstr)
      return matchdict 
  </code></pre>