11
Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.
Tôi có một danh sách các yếu tố chứa các ký tự đặc biệt. Tôi muốn chuyển đổi danh sách thành các ký tự chữ và số. Không có ký tự đặc biệt. my_list = ["on@3", "hai#", "thre%e"]]
đầu ra mong đợi của tôi là,
out_list = ["one","two","three"]
Tôi không thể đơn giản áp dụng
import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub['[^a-zA-Z0-9]+', '', _] for _ in my_list]
5 cho các mặt hàng này, xin vui lòng giúp đỡ.
Đã hỏi ngày 15 tháng 11 năm 2017 lúc 7:36Nov 15, 2017 at 7:36
3
Đây là một giải pháp khác:
import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub['[^a-zA-Z0-9]+', '', _] for _ in my_list]
output:
['on3', 'two', 'three']
Đã trả lời ngày 15 tháng 11 năm 2017 lúc 7:46Nov 15, 2017 at 7:46
Mahesh Kariamahesh KariaMahesh Karia
2.0251 Huy hiệu vàng11 Huy hiệu bạc21 Huy hiệu đồng1 gold badge11 silver badges21 bronze badges
Sử dụng phương thức
import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub['[^a-zA-Z0-9]+', '', _] for _ in my_list]
6 để áp dụng cùng một bảng dịch cho tất cả các chuỗi:removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
Phương pháp tĩnh
import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub['[^a-zA-Z0-9]+', '', _] for _ in my_list]
7 là một công cụ hữu ích để tạo ra bản đồ dịch; Hai đối số đầu tiên là các chuỗi trống vì bạn không thay thế các ký tự, chỉ xóa. Chuỗi thứ ba chứa tất cả các ký tự bạn muốn xóa.Demo:
>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
Đã trả lời ngày 15 tháng 11 năm 2017 lúc 7:43Nov 15, 2017 at 7:43
Martijn Pieters ♦ Martijn Pieters♦Martijn Pieters
991K276 Huy hiệu vàng3904 Huy hiệu bạc3253 Huy hiệu đồng276 gold badges3904 silver badges3253 bronze badges
3
thử cái này:
l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
Đã trả lời ngày 15 tháng 11 năm 2017 lúc 7:46Nov 15, 2017 at 7:46
Mahesh Kariamahesh Karia
l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
2.0251 Huy hiệu vàng11 Huy hiệu bạc21 Huy hiệu đồng
out_list = [ x.replace[y,''] for x in my_list for y in l if y in x ]
Sử dụng phương thức
import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub['[^a-zA-Z0-9]+', '', _] for _ in my_list]
6 để áp dụng cùng một bảng dịch cho tất cả các chuỗi:Phương pháp tĩnh
import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub['[^a-zA-Z0-9]+', '', _] for _ in my_list]
7 là một công cụ hữu ích để tạo ra bản đồ dịch; Hai đối số đầu tiên là các chuỗi trống vì bạn không thay thế các ký tự, chỉ xóa. Chuỗi thứ ba chứa tất cả các ký tự bạn muốn xóa.Nov 15, 2017 at 7:39
Đã trả lời ngày 15 tháng 11 năm 2017 lúc 7:43Van Peer
Martijn Pieters ♦ Martijn Pieters2 gold badges22 silver badges34 bronze badges
5
Vấn đề chung mà các lập trình viên phải đối mặt là loại bỏ các ký tự không mong muốn khỏi một chuỗi bằng Python. Nhưng đôi khi yêu cầu ở trên và yêu cầu loại bỏ hơn 1 nhân vật, nhưng một danh sách các nhân vật độc hại như vậy. Đây có thể ở dạng ký tự đặc biệt để xây dựng lại mật khẩu hợp lệ và nhiều ứng dụng khác có thể. Vì vậy, nhiệm vụ của chúng tôi là loại bỏ các ký tự không mong muốn khỏi chuỗi.
Xóa ký hiệu khỏi chuỗi bằng str.alsalnum []
Phương thức Python String isalnum [] kiểm tra xem tất cả các ký tự trong một chuỗi nhất định có phải là chữ và số hay không. Nó trả về một boolean là đúng - nếu tất cả các ký tự là chữ và khác hoặc sai - nếu một hoặc nhiều ký tự không phải là chữ và số.
Python3
['on3', 'two', 'three']
2['on3', 'two', 'three']
3 ['on3', 'two', 'three']
4['on3', 'two', 'three']
5['on3', 'two', 'three']
3 ['on3', 'two', 'three']
7['on3', 'two', 'three']
8 ['on3', 'two', 'three']
9removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
0 ['on3', 'two', 'three']
2removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
2 removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
3removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
4removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
5Output:
GeeksforGeeks
Xóa ký hiệu khỏi chuỗi bằng cách sử dụng thay thế [] & nbsp;
Người ta có thể sử dụng str.replace [] bên trong một vòng lặp để kiểm tra BAD_CHAR và sau đó thay thế nó bằng chuỗi trống do đó loại bỏ nó. Đây là cách tiếp cận cơ bản nhất và không hiệu quả trên quan điểm hiệu suất.
Python3
removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
6['on3', 'two', 'three']
3 removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
8removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
9>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
0>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
1>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
0>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
3>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
0>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
5>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
0>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
7____48>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
9['on3', 'two', 'three']
3 ['on3', 'two', 'three']
4removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
4l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
3l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
4 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
5 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
6['on3', 'two', 'three']
8 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
8removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
0 l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
0l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
1>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
9['on3', 'two', 'three']
3 l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
4removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
4l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
3l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
7 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
5 l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
9out_list = [ x.replace[y,''] for x in my_list for y in l if y in x ]
0Đầu ra: & nbsp;
Original String : Ge;ek*s:fo!r;Ge*e*k:s! Resultant list is : GeeksforGeeks
Xóa ký hiệu khỏi chuỗi bằng cách sử dụng Jop [] + Generator & nbsp;
Bằng cách sử dụng python tham gia [], chúng tôi làm lại chuỗi. Trong hàm Trình tạo, chúng tôi chỉ định logic để bỏ qua các ký tự trong bad_chars và do đó xây dựng một chuỗi mới không có ký tự xấu.
Python3
removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
6['on3', 'two', 'three']
3 removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
8removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
9>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
0>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
1>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
0>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
3>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
0>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
5>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
0>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
7____48>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
9['on3', 'two', 'three']
3 ['on3', 'two', 'three']
4removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
4l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
3l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
4 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
5 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
6['on3', 'two', 'three']
8 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
8removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
0 l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
0removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
4l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
3l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
7 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
5 l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
9out_list = [ x.replace[y,''] for x in my_list for y in l if y in x ]
0Đầu ra: & nbsp;
Original String : Ge;ek*s:fo!r;Ge*e*k:s! Resultant list is : GeeksforGeeks
Xóa ký hiệu khỏi chuỗi bằng cách sử dụng Jop [] + Generator & nbsp;translate[]
Bằng cách sử dụng python tham gia [], chúng tôi làm lại chuỗi. Trong hàm Trình tạo, chúng tôi chỉ định logic để bỏ qua các ký tự trong bad_chars và do đó xây dựng một chuỗi mới không có ký tự xấu.
Python3
>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
9['on3', 'two', 'three']
3 Original String : Ge;ek*s:fo!r;Ge*e*k:s! Resultant list is : GeeksforGeeks4
['on3', 'two', 'three']
8 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
8removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
0 >>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
9removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
2Xóa ký hiệu khỏi chuỗi bằng cách sử dụng dịch [] & nbsp;
>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
9['on3', 'two', 'three']
3 ['on3', 'two', 'three']
4removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
4l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
3l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
4 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
5 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
6['on3', 'two', 'three']
8 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
8removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
0 l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
0l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
1>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
9['on3', 'two', 'three']
3 l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
4removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
4l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
3l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
7 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
5 l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
9out_list = [ x.replace[y,''] for x in my_list for y in l if y in x ]
0Đầu ra: & nbsp;
removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
4l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
3l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
7 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
5 l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
9out_list = [ x.replace[y,''] for x in my_list for y in l if y in x ]
0Đầu ra: & nbsp;
Xóa ký hiệu khỏi chuỗi bằng cách sử dụng Jop [] + Generator & nbsp;Bằng cách sử dụng python tham gia [], chúng tôi làm lại chuỗi. Trong hàm Trình tạo, chúng tôi chỉ định logic để bỏ qua các ký tự trong bad_chars và do đó xây dựng một chuỗi mới không có ký tự xấu. filter[]
>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
9['on3', 'two', 'three']
3 Original String : Ge;ek*s:fo!r;Ge*e*k:s! Resultant list is : GeeksforGeeks4
['on3', 'two', 'three']
8 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
8removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
0 >>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
9removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
2Python3
Xóa ký hiệu khỏi chuỗi bằng cách sử dụng dịch [] & nbsp;
Cách thanh lịch nhất để thực hiện nhiệm vụ cụ thể này, phương pháp này về cơ bản được sử dụng để đạt được giải pháp cho loại vấn đề này, chúng ta có thể dịch từng BAD_CHAR thành một chuỗi trống và lấy chuỗi được lọc.
removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
4l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
3l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
4 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
5 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
6['on3', 'two', 'three']
8 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
8removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
0 l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
0import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub['[^a-zA-Z0-9]+', '', _] for _ in my_list]
85import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub['[^a-zA-Z0-9]+', '', _] for _ in my_list]
86removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
4l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
3l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
7 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
5 l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
9out_list = [ x.replace[y,''] for x in my_list for y in l if y in x ]
0Output:
Original String : Ge;ek*s:fo!r;Ge*e*k:s! Resultant list is : GeeksforGeeks
Xóa ký hiệu khỏi chuỗi bằng hàm re.sub []: & nbsp;re.sub[] function:
Các biểu thức chính quy được sử dụng để xác định ký tự xấu trong hàm chuỗi và re.sub được sử dụng để thay thế bad_char từ chuỗi. & Nbsp;
Python3
import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub['[^a-zA-Z0-9]+', '', _] for _ in my_list]
10 import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub['[^a-zA-Z0-9]+', '', _] for _ in my_list]
94['on3', 'two', 'three']
5['on3', 'two', 'three']
3 ['on3', 'two', 'three']
4import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub['[^a-zA-Z0-9]+', '', _] for _ in my_list]
98['on3', 'two', 'three']
3 removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
8['on3', 'two', 'three']
01>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
0['on3', 'two', 'three']
03____40>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
5>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
0['on3', 'two', 'three']
07404047474removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
4l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
3['on3', 'two', 'three']
13 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
5 ['on3', 'two', 'three']
15['on3', 'two', 'three']
16['on3', 'two', 'three']
3 import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub['[^a-zA-Z0-9]+', '', _] for _ in my_list]
42['on3', 'two', 'three']
8 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
8removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
0 ['on3', 'two', 'three']
22l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
1['on3', 'two', 'three']
16l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
55____23 ['on3', 'two', 'three']
27['on3', 'two', 'three']
28['on3', 'two', 'three']
3 ['on3', 'two', 'three']
30['on3', 'two', 'three']
31['on3', 'two', 'three']
32removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
4l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
3['on3', 'two', 'three']
35 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
5 l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
9['on3', 'two', 'three']
38Output:
import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub['[^a-zA-Z0-9]+', '', _] for _ in my_list]
3Xóa ký hiệu khỏi chuỗi bằng cách sử dụng trong, không phải trong các toán tử
Trong và không trong các toán tử được sử dụng để kiểm tra sự hiện diện của các ký tự không mong muốn trong chuỗi.
Python3
removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
6['on3', 'two', 'three']
3 removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
8removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
9>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
0>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
1>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
0>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
3>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
0>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
5>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
0>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
7____48>>> my_list = ["on@3", "two#", "thre%e"]
>>> removetable = str.maketrans['', '', '@#%']
>>> [s.translate[removetable] for s in my_list]
['on3', 'two', 'three']
9['on3', 'two', 'three']
3 ['on3', 'two', 'three']
4removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
4 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
3l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
4 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
5 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
6['on3', 'two', 'three']
60['on3', 'two', 'three']
3['on3', 'two', 'three']
62['on3', 'two', 'three']
8 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
8removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
0 ['on3', 'two', 'three']
66l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
1removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
2 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
8import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub['[^a-zA-Z0-9]+', '', _] for _ in my_list]
00 removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
0 l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
0['on3', 'two', 'three']
73['on3', 'two', 'three']
60l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
5['on3', 'two', 'three']
3['on3', 'two', 'three']
27removetable = str.maketrans['', '', '@#%']
out_list = [s.translate[removetable] for s in my_list]
4 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
3l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
7 l_in = ["on@3", "two#", "thre%e"]
l_out = [''.join[e for e in string if e.isalnum[]] for string in l_in]
print l_out
>['on3', 'two', 'three']
5 l = ['@','#','%']
out_list = []
for x in my_list:
for y in l:
if y in x:
x = x.replace[y,'']
out_list.append[x]
break
9['on3', 'two', 'three']
83Đầu ra
import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub['[^a-zA-Z0-9]+', '', _] for _ in my_list]
4