<s> from __future__ import print_function <EOL> from difflib import SequenceMatcher <EOL> import json <EOL> import os <EOL> import random <EOL> import string <EOL> import sys <EOL> def rankListByString ( inputList , queryString ) : <EOL> scores = [ ] <EOL> for listString in inputList : scores . append ( ( int ( <NUM_LIT:1000> * SequenceMatcher ( None , listString . lower ( ) , queryString . lower ( ) ) . ratio ( ) ) , listString ) ) <EOL> rankedList = [ ] <EOL> for score , listString in sorted ( scores ) : rankedList . append ( listString ) <EOL> rankedList . reverse ( ) <EOL> return rankedList <EOL> def getRandomString ( n ) : <EOL> return '<STR_LIT>' . join ( random . SystemRandom ( ) . choice ( string . uppercase + string . digits ) for _ in xrange ( n ) ) <EOL> def findMostSimilar ( referenceList , queryString ) : <EOL> score = <NUM_LIT:0> <EOL> for referenceString in referenceList : <EOL> queryScore = int ( <NUM_LIT:100> * SequenceMatcher ( None , referenceString . lower ( ) , queryString . lower ( ) ) . ratio ( ) ) <EOL> if queryScore > score : <EOL> score = queryScore <EOL> matchString = referenceString <EOL> return matchString </s>
