回答編集履歴
4
Update
answer
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
list_2 = ['a','b','c']
|
4
4
|
|
5
5
|
print(sum(
|
6
|
-
|
6
|
+
[list_1[i:i+len(list_2)] == list_2 for i in range(len(list_1)-len(list_2)+1)]))
|
7
7
|
|
8
8
|
#
|
9
9
|
2
|
@@ -12,7 +12,7 @@
|
|
12
12
|
list_2 = ['a','a']
|
13
13
|
|
14
14
|
print(sum(
|
15
|
-
|
15
|
+
[list_1[i:i+len(list_2)] == list_2 for i in range(len(list_1)-len(list_2)+1)]))
|
16
16
|
|
17
17
|
#
|
18
18
|
2
|
3
Update
answer
CHANGED
@@ -3,8 +3,7 @@
|
|
3
3
|
list_2 = ['a','b','c']
|
4
4
|
|
5
5
|
print(sum(
|
6
|
-
|
6
|
+
i == list_2 for i in [list_1[i:i+len(list_2)] for i in range(len(list_1)-len(list_2)+1)]))
|
7
|
-
if i == list_2))
|
8
7
|
|
9
8
|
#
|
10
9
|
2
|
@@ -13,8 +12,7 @@
|
|
13
12
|
list_2 = ['a','a']
|
14
13
|
|
15
14
|
print(sum(
|
16
|
-
|
15
|
+
i == list_2 for i in [list_1[i:i+len(list_2)] for i in range(len(list_1)-len(list_2)+1)]))
|
17
|
-
if i == list_2))
|
18
16
|
|
19
17
|
#
|
20
18
|
2
|
2
Update
answer
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
```python
|
2
|
-
import re
|
3
|
-
|
4
2
|
list_1 = ['a','b','c','d','e','a','b','c']
|
5
3
|
list_2 = ['a','b','c']
|
6
4
|
|
5
|
+
print(sum(
|
7
|
-
|
6
|
+
1 for i in [list_1[i:i+len(list_2)] for i in range(len(list_1)-len(list_2)+1)]
|
8
|
-
|
7
|
+
if i == list_2))
|
9
8
|
|
10
9
|
#
|
11
10
|
2
|
@@ -13,9 +12,32 @@
|
|
13
12
|
list_1 = ['a','a','a']
|
14
13
|
list_2 = ['a','a']
|
15
14
|
|
15
|
+
print(sum(
|
16
|
-
|
16
|
+
1 for i in [list_1[i:i+len(list_2)] for i in range(len(list_1)-len(list_2)+1)]
|
17
|
-
|
17
|
+
if i == list_2))
|
18
18
|
|
19
19
|
#
|
20
20
|
2
|
21
|
-
```
|
21
|
+
```
|
22
|
+
|
23
|
+
~~~```python~~~
|
24
|
+
~~~import re
|
25
|
+
~~~
|
26
|
+
~~~list_1 = ['a','b','c','d','e','a','b','c']~~~
|
27
|
+
~~~list_2 = ['a','b','c']~~~
|
28
|
+
|
29
|
+
~~~str_1, str_2 = '\0'.join(list_1), '\0'.join(list_2)~~~
|
30
|
+
~~~print(len(re.findall(rf'(?={str_2})', str_1)))~~~
|
31
|
+
~~~
|
32
|
+
~~~#~~~
|
33
|
+
~~~2~~~
|
34
|
+
|
35
|
+
~~~list_1 = ['a','a','a']~~~
|
36
|
+
~~~list_2 = ['a','a']~~~
|
37
|
+
|
38
|
+
~~~str_1, str_2 = '\0'.join(list_1), '\0'.join(list_2)~~~
|
39
|
+
~~~print(len(re.findall(rf'(?={str_2})', str_1)))~~~
|
40
|
+
~~~
|
41
|
+
~~~#~~~
|
42
|
+
~~~2~~~
|
43
|
+
~~~```~~~
|
1
Update
answer
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
list_1 = ['a','b','c','d','e','a','b','c']
|
5
5
|
list_2 = ['a','b','c']
|
6
6
|
|
7
|
-
str_1, str_2 = ''.join(list_1), ''.join(list_2)
|
7
|
+
str_1, str_2 = '\0'.join(list_1), '\0'.join(list_2)
|
8
8
|
print(len(re.findall(rf'(?={str_2})', str_1)))
|
9
9
|
|
10
10
|
#
|
@@ -13,7 +13,7 @@
|
|
13
13
|
list_1 = ['a','a','a']
|
14
14
|
list_2 = ['a','a']
|
15
15
|
|
16
|
-
str_1, str_2 = ''.join(list_1), ''.join(list_2)
|
16
|
+
str_1, str_2 = '\0'.join(list_1), '\0'.join(list_2)
|
17
17
|
print(len(re.findall(rf'(?={str_2})', str_1)))
|
18
18
|
|
19
19
|
#
|