replace
có thể làm điều gì đó mà bạn không muốn nếu chuỗi thứ hai có mặt tại một số vị trí:
s1 = 'AJYFAJYF'
s2 = 'AJ'
if s1.startswith[s2]:
s3 = s1.replace[s2, '']
s3
# 'YFYF'
Bạn có thể thêm một đối số bổ sung vào replace
để cho biết rằng bạn chỉ muốn một lần thay thế xảy ra:
if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
Hoặc bạn có thể sử dụng mô -đun re
:
import re
if s1.startswith[s2]:
s3 = re.sub['^' + s2, '', s1]
s3
# 'YFAJYF'
if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
0 là để đảm bảo rằng if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
1 nó chỉ được thay thế ở vị trí đầu tiên của if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
2.Tuy nhiên, một cách tiếp cận khác, được đề xuất trong các bình luận, sẽ là loại bỏ các ký tự
if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
3 đầu tiên từ if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
2:if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
Một số thử nghiệm sử dụng %thời gian ma thuật trong ipython [Python 2.7.12, ipython 5.1.0] cho thấy cách tiếp cận cuối cùng này nhanh hơn:
In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Phương pháp số 1: Sử dụng LOOP + Remove [] & NBSP; sự kết hợp của các chức năng trên có thể được sử dụng để thực hiện nhiệm vụ này. Trong đó, chúng tôi thực hiện loại bỏ các phần tử bằng cách sử dụng Remove [] và kiểm tra các phần tử tương tự bằng Loop. & NBSP;
The combination of above functionalities can be used to perform this task. In this, we perform the removal of elements using remove[] and check for similar elements using loop.
Python3
if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
5if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
6 if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
7if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
8if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
9import re
if s1.startswith[s2]:
s3 = re.sub['^' + s2, '', s1]
s3
# 'YFAJYF'
0if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
9import re
if s1.startswith[s2]:
s3 = re.sub['^' + s2, '', s1]
s3
# 'YFAJYF'
222import re
if s1.startswith[s2]:
s3 = re.sub['^' + s2, '', s1]
s3
# 'YFAJYF'
8if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
6 if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
7if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
1if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
9import re
if s1.startswith[s2]:
s3 = re.sub['^' + s2, '', s1]
s3
# 'YFAJYF'
0if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
9if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
8import re
if s1.startswith[s2]:
s3 = re.sub['^' + s2, '', s1]
s3
# 'YFAJYF'
7if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
7if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
8if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
9 In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
0 In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
1In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
2if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
7if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
8In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
5 In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
0 In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
1In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
8In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
9if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
6 The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']1
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']2
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']3
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']4
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']5
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']2
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']7
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']4
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']9
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']0
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']1
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']7
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']4
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']4
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']5
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']6
if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
7if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
8The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']9
In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
0 In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
1replace
2Đầu ra
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']
& nbsp; Phương thức #2: Sử dụng bộ đếm [] + phần tử [] & nbsp; Sự kết hợp của các hàm trên cung cấp tốc ký để giải quyết vấn đề này. Trong đó, chúng tôi trích xuất số lượng các phần tử trong cả hai danh sách và sau đó thực hiện tách bằng cách trích xuất bằng phần tử [].
Method #2 : Using Counter[] + elements[]
The combination of the above functions provides a shorthand to solve this problem. In this, we extract the count of elements in both list and then perform separation by their extraction using element[].
Python3
replace
3 replace
4replace
5 replace
6
if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
5if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
6 if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
7if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
8if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
9import re
if s1.startswith[s2]:
s3 = re.sub['^' + s2, '', s1]
s3
# 'YFAJYF'
0if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
9import re
if s1.startswith[s2]:
s3 = re.sub['^' + s2, '', s1]
s3
# 'YFAJYF'
222import re
if s1.startswith[s2]:
s3 = re.sub['^' + s2, '', s1]
s3
# 'YFAJYF'
8if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
6 if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
7if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
1if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
9import re
if s1.startswith[s2]:
s3 = re.sub['^' + s2, '', s1]
s3
# 'YFAJYF'
0if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
9if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
8import re
if s1.startswith[s2]:
s3 = re.sub['^' + s2, '', s1]
s3
# 'YFAJYF'
7if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
7if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
8if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
9 In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
0 In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
1In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
2if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
7if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
8In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
5 In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
0 In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
1In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
8In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
9if s1.startswith[s2]:
s3 = s1.replace[s2, '', 1]
s3
# 'YFAJYF'
6 The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']1
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']2
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']3
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']4
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']5
if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
7if s1.startswith[s2]:
s3 = s1[len[s2]:]
s3
# 'YFAJYF'
8The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']9
In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
0 In [1]: s1 = 'AJYFAJYF'
In [2]: s2 = 'AJ'
In [3]: %timeit s3 = s1[len[s2]:]
The slowest run took 24.47 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.7 ns per loop
In [4]: %timeit s3 = s1[len[s2]:]
The slowest run took 32.58 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.8 ns per loop
In [5]: %timeit s3 = s1[len[s2]:]
The slowest run took 21.81 times longer than the fastest. This could mean that an intermediate result is being cached.
10000000 loops, best of 3: 87.4 ns per loop
In [6]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.64 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 230 ns per loop
In [7]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 17.79 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 228 ns per loop
In [8]: %timeit s3 = s1.replace[s2, '', 1]
The slowest run took 16.27 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 234 ns per loop
In [9]: import re
In [10]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 82.02 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.85 µs per loop
In [11]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 12.82 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.86 µs per loop
In [12]: %timeit s3 = re.sub['^' + s2, '', s1]
The slowest run took 13.08 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 1.84 µs per loop
1replace
2
Đầu ra
The original list 1 : ['gfg', 'is', 'best', 'for', 'CS'] The original list 2 : ['preferred', 'is', 'gfg'] The Subtracted list is : ['best', 'for', 'CS']