''' Sample program for assertion. This solves the longest common substring problem ''' def substrings(str): ''' given a string "str", return a list containing all substrings of it ''' assert(type(str) == type("")) result = [] for i in range(len(str)): for j in range(len(str)): if j>i and str[i:j+1] not in result: result.append(str[i:j+1]) return(result) if __name__ == '__main__': import sys assert len(sys.argv) == 3 s1 = sys.argv[1] s2 = sys.argv[2] assert(type(s1) == type("")) assert(type(s2) == type("")) res1=substrings(s1) res2=substrings(s2) common = [""] for substr in res1: if substr in res2: if len(substr) >= len(common[0:]): del common[0:] assert(len(common) == 0) common.append(substr) elif len(substr) == len(common[0]): assert( len(common[-1]) == len(substr)) # common[-1] is the last element of 'common' common.append(substr) else: pass # do nothing print common