Skip to content

Commit 1eeb1e0

Browse files
authored
Update genericRoutines.py
1 parent fc710d6 commit 1eeb1e0

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

genericRoutines.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def super_reduced_string(s):
177177
def 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

183183
def 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

0 commit comments

Comments
 (0)