Cải thiện bài viết
Lưu bài viết
Cải thiện bài viết
Lưu bài viết
Đọc
Method #1 : Using loop
This is one of the ways in which this task can be performed. In this, we iterate through the list and then check for non presence of vowels and filter.
Python3
Bàn luận
Đôi khi, trong khi làm việc với Python, chúng ta có thể gặp vấn đề trong đó chúng ta muốn loại bỏ tất cả các nguyên âm không khỏi chuỗi. Đây là câu hỏi và giải pháp khá phổ biến cho nó rất hữu ích trong lập trình cạnh tranh và lập trình hàng ngày. Hãy thảo luận về một số cách nhất định trong đó nhiệm vụ này có thể được thực hiện. Trong đó, chúng tôi lặp lại thông qua danh sách và sau đó kiểm tra không có sự hiện diện của nguyên âm và bộ lọc. & NBSP;
test_str
=
"Gfg is best for geeks"
print
[
"The original string is : "
The original string is : Gfg is best for geeks String after consonants removal : ieoee0
The original string is : Gfg is best for geeks String after consonants removal : ieoee1
The original string is : Gfg is best for geeks String after consonants removal : ieoee2
=
The original string is : Gfg is best for geeks String after consonants removal : ieoee4
eeeoee - A oue iee oa o ee5
eeeoee - A oue iee oa o ee6
The original string is : Gfg is best for geeks String after consonants removal : ieoee6
eeeoee - A oue iee oa o ee8
The original string is : Gfg is best for geeks String after consonants removal : ieoee5
The original string is : Gfg is best for geeks String after consonants removal : ieoee6
The original string is : Gfg is best for geeks String after consonants removal : ieoee7
The original string is : Gfg is best for geeks String after consonants removal : ieoee8
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
eeeoee - A oue iee oa o ee0
The original string is : Gfg is best for geeks String after consonants removal : ieoee6
The original string is : Gfg is best for geeks String after consonants removal : ieoee7
eeeoee - A oue iee oa o ee3
eeeoee - A oue iee oa o ee4
The original string is : Gfg is best for geeks
String after consonants removal : ieoee
2=
eeeoee - A oue iee oa o ee
1
The original string is : Gfg is best for geeks String after consonants removal : ieoee
print
[
eeeoee - A oue iee oa o ee4
The original string is : Gfg is best for geeks String after consonants removal : ieoee0
eeeoee - A oue iee oa o ee6
eeeoee - A oue iee oa o ee7
Method #2 : Using list comprehension
This is one of the ways in which this task can be performed. In this, we iterate through the list and then filter out vowels in similar manner but in one-liner.
Python3
Bàn luận
Đôi khi, trong khi làm việc với Python, chúng ta có thể gặp vấn đề trong đó chúng ta muốn loại bỏ tất cả các nguyên âm không khỏi chuỗi. Đây là câu hỏi và giải pháp khá phổ biến cho nó rất hữu ích trong lập trình cạnh tranh và lập trình hàng ngày. Hãy thảo luận về một số cách nhất định trong đó nhiệm vụ này có thể được thực hiện. Trong đó, chúng tôi lặp lại thông qua danh sách và sau đó kiểm tra không có sự hiện diện của nguyên âm và bộ lọc. & NBSP;
test_str
=
"Gfg is best for geeks"
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
eeeoee - A oue iee oa o ee0
The original string is : Gfg is best for geeks String after consonants removal : ieoee6
The original string is : Gfg is best for geeks String after consonants removal : ieoee7
eeeoee - A oue iee oa o ee3
eeeoee - A oue iee oa o ee4
The original string is : Gfg is best for geeks
String after consonants removal : ieoee
2=
eeeoee - A oue iee oa o ee
1
The original string is : Gfg is best for geeks String after consonants removal : ieoee
print
[
eeeoee - A oue iee oa o ee4
The original string is : Gfg is best for geeks String after consonants removal : ieoee0
eeeoee - A oue iee oa o ee6
eeeoee - A oue iee oa o ee7
Đầu raO[n]
& nbsp; Phương pháp #2: Sử dụng danh sách hiểu & nbsp; Đây là một trong những cách mà nhiệm vụ này có thể được thực hiện. Trong đó, chúng tôi lặp lại thông qua danh sách và sau đó lọc các nguyên âm theo cách tương tự nhưng trong một liner. & Nbsp;O[n]
nguyên âm = ['a', 'e', 'i', 'o', 'u'].
cho x trong c. thấp hơn[]:.
nguyên âm = ['a', 'e', 'i', 'o', 'u'].
cho x trong c. thấp hơn[]:.
Nếu x trong nguyên âm:.
Examples:
Báo chí = Báo chí. thay thế [x, ""]. str= “Welcome to geeksforgeeks”
Output: eoe o eeoeeTrả lại báo .. str= “What is your name?”
Output: a i ou ae?
Cải thiện bài viết Traverse all the characters of the string, if the character is a consonant then remove it from the final answer.
Lưu bài viết
Java
"Gfg is best for geeks"
1 =
81
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
"Gfg is best for geeks"
4 =
85=
88print
9 =
90=
91
The original string is : Gfg is best for geeks String after consonants removal : ieoee09
The original string is : Gfg is best for geeks String after consonants removal : ieoee50
The original string is : Gfg is best for geeks String after consonants removal : ieoee51
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
The original string is : Gfg is best for geeks String after consonants removal : ieoee64
"Gfg is best for geeks"
4 The original string is : Gfg is best for geeks String after consonants removal : ieoee66
The original string is : Gfg is best for geeks String after consonants removal : ieoee67
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
print
0eeeoee - A oue iee oa o ee20
eeeoee - A oue iee oa o ee21
eeeoee - A oue iee oa o ee20
"Gfg is best for geeks"
16"Gfg is best for geeks"
1 "Gfg is best for geeks"
18
eeeoee - A oue iee oa o ee20
"Gfg is best for geeks"
16"Gfg is best for geeks"
1 "Gfg is best for geeks"
18
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
"The original string is : "
8eeeoee - A oue iee oa o ee5
print
9 "Gfg is best for geeks"
27=
91The original string is : Gfg is best for geeks String after consonants removal : ieoee09__150150151
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
print
0eeeoee - A oue iee oa o ee5
The original string is : Gfg is best for geeks String after consonants removal : ieoee05
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
The original string is : Gfg is best for geeks String after consonants removal : ieoee64
"Gfg is best for geeks"
4 The original string is : Gfg is best for geeks String after consonants removal : ieoee66
"Gfg is best for geeks"
38eeeoee - A oue iee oa o ee5
The original string is : Gfg is best for geeks String after consonants removal : ieoee29
Độ phức tạp về thời gian: O [n] trong đó n là chiều dài của không gian chuỗi: O [1]
Làm thế nào để bạn loại bỏ các phụ âm khỏi một chuỗi?
Cách tiếp cận: Traverse tất cả các ký tự của chuỗi, nếu ký tự là một phụ âm thì hãy xóa nó khỏi câu trả lời cuối cùng. Dưới đây là việc thực hiện phương pháp trên: Java. Python3.
The original string is : Gfg is best for geeks String after consonants removal : ieoee44
The original string is : Gfg is best for geeks String after consonants removal : ieoee45
The original string is : Gfg is best for geeks String after consonants removal : ieoee44
The original string is : Gfg is best for geeks String after consonants removal : ieoee47
The original string is : Gfg is best for geeks String after consonants removal : ieoee48
The original string is : Gfg is best for geeks String after consonants removal : ieoee09
The original string is : Gfg is best for geeks String after consonants removal : ieoee50
The original string is : Gfg is best for geeks String after consonants removal : ieoee51
The original string is : Gfg is best for geeks String after consonants removal : ieoee44
The original string is : Gfg is best for geeks String after consonants removal : ieoee53
print
8"The original string is : "
8
eeeoee - A oue iee oa o ee5
"The original string is : "
8Bạn có thể xóa các chữ cái khỏi một chuỗi trong Python không?
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
"The original string is : "
8The original string is : Gfg is best for geeks String after consonants removal : ieoee9
The original string is : Gfg is best for geeks String after consonants removal : ieoee64
"Gfg is best for geeks"
4 The original string is : Gfg is best for geeks String after consonants removal : ieoee66
The original string is : Gfg is best for geeks String after consonants removal : ieoee67
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
print
0eeeoee - A oue iee oa o ee5
The original string is : Gfg is best for geeks String after consonants removal : ieoee71
print
8
The original string is : Gfg is best for geeks String after consonants removal : ieoee73
The original string is : Gfg is best for geeks String after consonants removal : ieoee74
[
1eeeoee - A oue iee oa o ee5
The original string is : Gfg is best for geeks String after consonants removal : ieoee77
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
"The original string is : "
8"The original string is : "
8
Python3
eeeoee - A oue iee oa o ee20
eeeoee - A oue iee oa o ee21
eeeoee - A oue iee oa o ee20
"Gfg is best for geeks"
16"Gfg is best for geeks"
1 "Gfg is best for geeks"
18
eeeoee - A oue iee oa o ee5
print
9 "Gfg is best for geeks"
27=
91The original string is : Gfg is best for geeks String after consonants removal : ieoee09__150150151
"Gfg is best for geeks"
1 "Gfg is best for geeks"
18
eeeoee - A oue iee oa o ee5
print
9 "Gfg is best for geeks"
27=
91The original string is : Gfg is best for geeks String after consonants removal : ieoee09__150150151
The original string is : Gfg is best for geeks String after consonants removal : ieoee81
eeeoee - A oue iee oa o ee16
eeeoee - A oue iee oa o ee6
The original string is : Gfg is best for geeks String after consonants removal : ieoee92
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
eeeoee - A oue iee oa o ee20
=
eeeoee - A oue iee oa o ee222222
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
eeeoee - A oue iee oa o ee444____5
eeeoee - A oue iee oa o ee46
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
The original string is : Gfg is best for geeks String after consonants removal : ieoee5
eeeoee - A oue iee oa o ee49
The original string is : Gfg is best for geeks String after consonants removal : ieoee7
eeeoee - A oue iee oa o ee51
[
eeeoee - A oue iee oa o ee53
[
eeeoee - A oue iee oa o ee6
eeeoee - A oue iee oa o ee56
eeeoee - A oue iee oa o ee5
eeeoee - A oue iee oa o ee58
=
eeeoee - A oue iee oa o ee13
eeeoee - A oue iee oa o ee61
eeeoee - A oue iee oa o ee5
The original string is : Gfg is best for geeks String after consonants removal : ieoee5
eeeoee - A oue iee oa o ee64
The original string is : Gfg is best for geeks String after consonants removal : ieoee7
eeeoee - A oue iee oa o ee51
[
eeeoee - A oue iee oa o ee53
eeeoee - A oue iee oa o ee69
‘
The original string is : Gfg is best for geeks String after consonants removal : ieoee44
eeeoee - A oue iee oa o ee58
=
The original string is : Gfg is best for geeks String after consonants removal : ieoee95
[
1The original string is : Gfg is best for geeks String after consonants removal : ieoee44
eeeoee - A oue iee oa o ee84
eeeoee - A oue iee oa o ee85
eeeoee - A oue iee oa o ee5
eeeoee - A oue iee oa o ee0
[
eeeoee - A oue iee oa o ee89
"Gfg is best for geeks"
6eeeoee - A oue iee oa o ee6
eeeoee - A oue iee oa o ee929__
‘
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
print
9 eeeoee - A oue iee oa o ee03
eeeoee - A oue iee oa o ee0
eeeoee - A oue iee oa o ee05
=
=
____eeeoee - A oue iee oa o ee08
eeeoee - A oue iee oa o ee09
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
eeeoee - A oue iee oa o ee6
=
The original string is : Gfg is best for geeks String after consonants removal : ieoee74
[
1The original string is : Gfg is best for geeks String after consonants removal : ieoee9
print
eeeoee - A oue iee oa o ee17
eeeoee - A oue iee oa o ee6
eeeoee - A oue iee oa o ee19
C#
eeeoee - A oue iee oa o ee20
eeeoee - A oue iee oa o ee21
eeeoee - A oue iee oa o ee20
eeeoee - A oue iee oa o ee23
eeeoee - A oue iee oa o ee20
eeeoee - A oue iee oa o ee25
eeeoee - A oue iee oa o ee20
eeeoee - A oue iee oa o ee27
"Gfg is best for geeks"
1
eeeoee - A oue iee oa o ee29
"Gfg is best for geeks"
4
eeeoee - A oue iee oa o ee31
"Gfg is best for geeks"
6"Gfg is best for geeks"
7 "Gfg is best for geeks"
8print
0
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
eeeoee - A oue iee oa o ee0
print
3print
4 print
5print
6eeeoee - A oue iee oa o ee8
eeeoee - A oue iee oa o ee5
print
9 [
0[
1The original string is : Gfg is best for geeks String after consonants removal : ieoee9
eeeoee - A oue iee oa o ee0
print
3[
5 print
5[
7eeeoee - A oue iee oa o ee8
eeeoee - A oue iee oa o ee5
print
9 [
0[
1The original string is : Gfg is best for geeks String after consonants removal : ieoee9
eeeoee - A oue iee oa o ee0
print
3[
5 print
5[
7eeeoee - A oue iee oa o ee8
"The original string is : "
8
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
print
9 "The original string is : "
5[
1print
0
"Gfg is best for geeks"
4
eeeoee - A oue iee oa o ee64
eeeoee - A oue iee oa o ee16
eeeoee - A oue iee oa o ee64
eeeoee - A oue iee oa o ee67
Các
Các
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
eeeoee - A oue iee oa o ee64
eeeoee - A oue iee oa o ee95
The original string is : Gfg is best for geeks String after consonants removal : ieoee50
[
1The original string is : Gfg is best for geeks String after consonants removal : ieoee9
print
0The original string is : Gfg is best for geeks String after consonants removal : ieoee9
The original string is : Gfg is best for geeks String after consonants removal : ieoee5
[
The original string is : Gfg is best for geeks String after consonants removal : ieoee37
test_str
02eeeoee - A oue iee oa o ee5
eeeoee - A oue iee oa o ee31
test_str
07"The original string is : "
5[
1eeeoee - A oue iee oa o ee5
print
0eeeoee - A oue iee oa o ee5
The original string is : Gfg is best for geeks String after consonants removal : ieoee5
[
The original string is : Gfg is best for geeks String after consonants removal : ieoee37
test_str
14print
8print
0
The original string is : Gfg is best for geeks String after consonants removal : ieoee44
test_str
07[
0[
1The original string is : Gfg is best for geeks String after consonants removal : ieoee44
eeeoee - A oue iee oa o ee84
[
1print
8"The original string is : "
8
print
8
eeeoee - A oue iee oa o ee0
test_str
19eeeoee - A oue iee oa o ee5
"The original string is : "
8eeeoee - A oue iee oa o ee5
print
0print
8test_str
39
eeeoee - A oue iee oa o ee5
"The original string is : "
8The original string is : Gfg is best for geeks String after consonants removal : ieoee9
"The original string is : "
8The original string is : Gfg is best for geeks String after consonants removal : ieoee9
print
9 eeeoee - A oue iee oa o ee03
"The original string is : "
8
eeeoee - A oue iee oa o ee0
eeeoee - A oue iee oa o ee05
=
=
____eeeoee - A oue iee oa o ee08
eeeoee - A oue iee oa o ee09
print
0
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
eeeoee - A oue iee oa o ee6
=
The original string is : Gfg is best for geeks String after consonants removal : ieoee74
[
1The original string is : Gfg is best for geeks String after consonants removal : ieoee9
test_str
61"The original string is : "
8
"The original string is : "
8
eeeoee - A oue iee oa o ee
20 eeeoee - A oue iee oa o ee
21
test_str
64
eeeoee - A oue iee oa o ee20
eeeoee - A oue iee oa o ee23
eeeoee - A oue iee oa o ee20
eeeoee - A oue iee oa o ee25
eeeoee - A oue iee oa o ee20
eeeoee - A oue iee oa o ee27
"Gfg is best for geeks"
1
eeeoee - A oue iee oa o ee29
test_str
65"The original string is : "
8
"Gfg is best for geeks"
4
eeeoee - A oue iee oa o ee31
"Gfg is best for geeks"
6"Gfg is best for geeks"
7 "Gfg is best for geeks"
8The original string is : Gfg is best for geeks String after consonants removal : ieoee9
eeeoee - A oue iee oa o ee0
print
3print
4 print
5print
6eeeoee - A oue iee oa o ee8
eeeoee - A oue iee oa o ee5
=
01test_str
71The original string is : Gfg is best for geeks String after consonants removal : ieoee09
=
04The original string is : Gfg is best for geeks String after consonants removal : ieoee09
=
06The original string is : Gfg is best for geeks String after consonants removal : ieoee09
=
08The original string is : Gfg is best for geeks String after consonants removal : ieoee09
=
10The original string is : Gfg is best for geeks String after consonants removal : ieoee09
test_str
81The original string is : Gfg is best for geeks String after consonants removal : ieoee09
=
14The original string is : Gfg is best for geeks String after consonants removal : ieoee09
=
16The original string is : Gfg is best for geeks String after consonants removal : ieoee09
=
18The original string is : Gfg is best for geeks String after consonants removal : ieoee09
=
20=
21eeeoee - A oue iee oa o ee5
print
9 [
0[
1The original string is : Gfg is best for geeks String after consonants removal : ieoee9
eeeoee - A oue iee oa o ee0
print
3[
5 print
5[
7eeeoee - A oue iee oa o ee8
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
print
9 "The original string is : "
5[
1"Gfg is best for geeks"
4
eeeoee - A oue iee oa o ee64
eeeoee - A oue iee oa o ee16
eeeoee - A oue iee oa o ee64
eeeoee - A oue iee oa o ee67
Các
=
45test_str
07[
0[
1
=
45
eeeoee - A oue iee oa o ee84
[
1print
8"The original string is : "
8
=
32"The original string is : "
8
Các
print
8test_str
39
=
32"The original string is : "
8
eeeoee - A oue iee oa o ee5
"The original string is : "
8The original string is : Gfg is best for geeks String after consonants removal : ieoee9
eeeoee - A oue iee oa o ee64
eeeoee - A oue iee oa o ee95
The original string is : Gfg is best for geeks String after consonants removal : ieoee50
[
1test_str
65"The original string is : "
8
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
The original string is : Gfg is best for geeks String after consonants removal : ieoee5
[
The original string is : Gfg is best for geeks String after consonants removal : ieoee37
test_str
02test_str
65
The original string is : Gfg is best for geeks String after consonants removal : ieoee74
[
1test_str
65=
77
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
=
79Output:
eeeoee - A oue iee oa o ee
eeeoee - A oue iee oa o ee
5eeeoee - A oue iee oa o ee
31 test_str
07"The original string is : "
5[
1O[N]
Auxiliary Space: O[N]
eeeoee - A oue iee oa o ee5
The original string is : Gfg is best for geeks String after consonants removal : ieoee5
[
The original string is : Gfg is best for geeks String after consonants removal : ieoee37
test_str
14print
8eeeoee - A oue iee oa o ee
0 test_str
19
eeeoee - A oue iee oa o ee5
"The original string is : "
8=
82
eeeoee - A oue iee oa o ee5
eeeoee - A oue iee oa o ee0
test_str
35The original string is : Gfg is best for geeks String after consonants removal : ieoee9
print
0The original string is : Gfg is best for geeks String after consonants removal : ieoee64
"Gfg is best for geeks"
4 The original string is : Gfg is best for geeks String after consonants removal : ieoee66
test_str
51eeeoee - A oue iee oa o ee644____453
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
"The original string is : "
8The original string is : Gfg is best for geeks String after consonants removal : ieoee9
eeeoee - A oue iee oa o ee64
test_str
57The original string is : Gfg is best for geeks String after consonants removal : ieoee74
[
1The original string is : Gfg is best for geeks String after consonants removal : ieoee9
print
0eeeoee - A oue iee oa o ee5
"Gfg is best for geeks"
05The original string is : Gfg is best for geeks String after consonants removal : ieoee74
[
1eeeoee - A oue iee oa o ee5
"Gfg is best for geeks"
09The original string is : Gfg is best for geeks String after consonants removal : ieoee9
"The original string is : "
8"The original string is : "
8
C#
eeeoee - A oue iee oa o ee20
eeeoee - A oue iee oa o ee21
eeeoee - A oue iee oa o ee20
eeeoee - A oue iee oa o ee23
eeeoee - A oue iee oa o ee20
eeeoee - A oue iee oa o ee25
print
0
eeeoee - A oue iee oa o ee5
eeeoee - A oue iee oa o ee0
test_str
35The original string is : Gfg is best for geeks String after consonants removal : ieoee9
print
0eeeoee - A oue iee oa o ee5
print
9 "Gfg is best for geeks"
27=
91The original string is : Gfg is best for geeks String after consonants removal : ieoee09__150150151
The original string is : Gfg is best for geeks String after consonants removal : ieoee9
"The original string is : "
8The original string is : Gfg is best for geeks String after consonants removal : ieoee9
The original string is : Gfg is best for geeks String after consonants removal : ieoee64
"Gfg is best for geeks"
4 The original string is : Gfg is best for geeks String after consonants removal : ieoee66
"Gfg is best for geeks"
38The original string is : Gfg is best for geeks String after consonants removal : ieoee9
print
0eeeoee - A oue iee oa o ee5
"Gfg is best for geeks"
05The original string is : Gfg is best for geeks String after consonants removal : ieoee74
[
1eeeoee - A oue iee oa o ee5
"Gfg is best for geeks"
46The original string is : Gfg is best for geeks String after consonants removal : ieoee9
"The original string is : "
8"The original string is : "
8
Output:
eeeoee - A oue iee oa o ee
Độ phức tạp về thời gian: O [n] trong đó n là chiều dài của không gian chuỗi: O [1] O[n] where n is the length of string
Auxiliary Space: O[1]