-
Notifications
You must be signed in to change notification settings - Fork 0
/
substring_pattern.txt
60 lines (46 loc) · 1.11 KB
/
substring_pattern.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
------------- Faulty Logic (1)
s = "abaababaab" # to work on
char = s[0] # the index of the str to break/split on
sub = [] # list to store the substrings
current_sub = "" # str to store the current substring
for i in s:
if char == i and current_sub:
# Add the current substring to the list and start a new one
sub.append(current_sub)
current_sub = i
else:
# Add the character to the current substring
current_sub += i
# add the last str from the current to sub list
# if current is not empty
if current_sub:
sub.append(current_sub)
print(sub)
if len(s) == 1:
print("False")
elif set(sub) == {sub[0]}:
print("True")
else:
print("False")
------------------------------
------------- Faulty Logic (2)
- negative/positive lookahead
import re
s = "abcabcabcabc"
char = s[0]
count = 0
sub = []
for i in s:
if i == char:
print(i)
sub = re.split(f"(?<={i})", s) # faulty line
count += 1
empty = ''
for i in sub:
if i == empty:
sub.remove(empty)
print(sub)
if set(sub) == {sub[0]}:
print("True")
else:
print("False")