File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -177,7 +177,7 @@ def super_reduced_string(s):
177177def readfiles (filenames ):
178178 for f in filenames :
179179 with open (f ) as fr :
180- for line in open ( fr ) :
180+ for line in fr :
181181 yield line
182182
183183def grep (pattern , lines ):
@@ -191,3 +191,24 @@ def main(pattern, filenames):
191191 lines = readfiles (filenames )
192192 lines = grep (pattern , lines )
193193 printlines (lines )
194+
195+
196+ #########################################################################################################################
197+ # Find the longest non repeating substring in a string
198+ def max_substring (string ):
199+ last_substring = ''
200+ max_substring = ''
201+ for x in string :
202+ k = find_index (x ,last_substring )
203+ last_substring = last_substring [(k + 1 ):]+ x
204+ print (f'last substrin = { last_substring } ' )
205+ if len (last_substring ) > len (max_substring ):
206+ max_substring = last_substring
207+ return max_substring
208+ def find_index (x , lst ):
209+ k = 0
210+ while k < len (lst ):
211+ if lst [k ] == x :
212+ return k
213+ k += 1
214+ return - 1
You can’t perform that action at this time.
0 commit comments