I've created this function that looks for sequences in a list. If [1,2,3]
exists, it will print True
. I've tested the code and it works fine.
def looking_patt(pattern,cursor,found):
big_s = []
for i in range(1,101):
if i % 10 == 0:
big_s.extend([1,2,3])
else:
big_s.append(i)
# check control
print(big_s)
for i in big_s:
if i == pattern[cursor]:
cursor += 1
if cursor == len(pattern):
found.append(pattern)
print(found)
cursor = 0
else:
cursor = 0
print(len(found) > 0)
Part of the script (the for i in big_s:
) has been taken from an answer in this SO question this SO question.
How can it be improved?
I've created this function that looks for sequences in a list. If [1,2,3]
exists, it will print True
. I've tested the code and it works fine.
def looking_patt(pattern,cursor,found):
big_s = []
for i in range(1,101):
if i % 10 == 0:
big_s.extend([1,2,3])
else:
big_s.append(i)
# check control
print(big_s)
for i in big_s:
if i == pattern[cursor]:
cursor += 1
if cursor == len(pattern):
found.append(pattern)
print(found)
cursor = 0
else:
cursor = 0
print(len(found) > 0)
Part of the script (the for i in big_s:
) has been taken from an answer in this SO question.
How can it be improved?
I've created this function that looks for sequences in a list. If [1,2,3]
exists, it will print True
. I've tested the code and it works fine.
def looking_patt(pattern,cursor,found):
big_s = []
for i in range(1,101):
if i % 10 == 0:
big_s.extend([1,2,3])
else:
big_s.append(i)
# check control
print(big_s)
for i in big_s:
if i == pattern[cursor]:
cursor += 1
if cursor == len(pattern):
found.append(pattern)
print(found)
cursor = 0
else:
cursor = 0
print(len(found) > 0)
Part of the script (the for i in big_s:
) has been taken from an answer in this SO question.
How can it be improved?
code that looks Looking for a pattern in a list
I've created this function.
It that looks for sequences, in a list. If [1,2,3]
existexists, it will print True
. I've tested the code and it works fine.
def looking_patt(pattern,cursor,found):
big_s = []
for i in range(1,101):
if i % 10 == 0:
big_s.extend([1,2,3])
else:
big_s.append(i)
# check control
print(big_s)
for i in big_s:
if i == pattern[cursor]:
cursor += 1
if cursor == len(pattern):
found.append(pattern)
print(found)
cursor = 0
else:
cursor = 0
print(len(found) > 0)
Part of the script the(the for i in big_s:
) has been taken from the secondan answer in this SO'sSO question.
How can it be improved?
code that looks for a pattern
I've created this function.
It looks for sequences, in a list. If [1,2,3]
exist, it will print True
I've tested the code and it works fine
def looking_patt(pattern,cursor,found):
big_s = []
for i in range(1,101):
if i % 10 == 0:
big_s.extend([1,2,3])
else:
big_s.append(i)
# check control
print(big_s)
for i in big_s:
if i == pattern[cursor]:
cursor += 1
if cursor == len(pattern):
found.append(pattern)
print(found)
cursor = 0
else:
cursor = 0
print(len(found) > 0)
Part of the script the for i in big_s:
has been taken from the second answer in this SO's question.
How can it be improved?
Looking for a pattern in a list
I've created this function that looks for sequences in a list. If [1,2,3]
exists, it will print True
. I've tested the code and it works fine.
def looking_patt(pattern,cursor,found):
big_s = []
for i in range(1,101):
if i % 10 == 0:
big_s.extend([1,2,3])
else:
big_s.append(i)
# check control
print(big_s)
for i in big_s:
if i == pattern[cursor]:
cursor += 1
if cursor == len(pattern):
found.append(pattern)
print(found)
cursor = 0
else:
cursor = 0
print(len(found) > 0)
Part of the script (the for i in big_s:
) has been taken from an answer in this SO question.
How can it be improved?
I've created this function.
It looks for sequences, in a list. If [1,2,3]
exist, it will print True
I've tested the code and it works fine
def looking_patt(pattern,cursor,found):
big_s = []
for i in range(1,101):
if i % 10 == 0:
big_s.extend([1,2,3])
else:
big_s.append(i)
# check control
print(big_s)
for i in big_s:
if i == pattern[cursor]:
cursor += 1
if cursor == len(pattern):
found.append(pattern)
print(found)
cursor = 0
else:
cursor = 0
print(len(found) > 0)
Part of the script the for i in big_s:
has been taken from the second answer in this SO's question.
How can it be improved?
Thanks
I've created this function.
It looks for sequences, in a list. If [1,2,3]
exist, it will print True
I've tested the code and it works fine
def looking_patt(pattern,cursor,found):
big_s = []
for i in range(1,101):
if i % 10 == 0:
big_s.extend([1,2,3])
else:
big_s.append(i)
# check control
print(big_s)
for i in big_s:
if i == pattern[cursor]:
cursor += 1
if cursor == len(pattern):
found.append(pattern)
print(found)
cursor = 0
else:
cursor = 0
print(len(found) > 0)
Part of the script the for i in big_s:
has been taken from the second answer in this SO's question.
How can it be improved?
Thanks
I've created this function.
It looks for sequences, in a list. If [1,2,3]
exist, it will print True
I've tested the code and it works fine
def looking_patt(pattern,cursor,found):
big_s = []
for i in range(1,101):
if i % 10 == 0:
big_s.extend([1,2,3])
else:
big_s.append(i)
# check control
print(big_s)
for i in big_s:
if i == pattern[cursor]:
cursor += 1
if cursor == len(pattern):
found.append(pattern)
print(found)
cursor = 0
else:
cursor = 0
print(len(found) > 0)
Part of the script the for i in big_s:
has been taken from the second answer in this SO's question.
How can it be improved?