+ 1

How do you remove things that are not letters or numbers

Using the remove function

28th Apr 2021, 4:38 PM
dalton mutugi
dalton mutugi - avatar
4 Answers
+ 1
x="@#213anas45%&+" y='' for i in x: if i.isalpha() or i.isdigit(): y+=i print(y)
28th Apr 2021, 6:05 PM
Shadoff - avatar
+ 1
Using the functional programming, the filter function accepts two arguments : function : iterable So, in a string X, you can filter your result R as X = "hks12%" R = list(filter(lambda x:x.isalnum(), X)) print(*R)
28th Apr 2021, 7:31 PM
Mirielle - avatar
By using the index of the element. Syntax: del <List_name>[<index>] or del <List_name>[<start>:<stop>] May this will help you.
28th Apr 2021, 4:54 PM
Aman Jain
Aman Jain - avatar
If you wanna solve your problem in O(n) then run a loop in which each iteration check if a character lands in an alphanumeric category(not underscore)or not, otherwise pop it.
28th Apr 2021, 4:56 PM
Rahul Saxena
Rahul Saxena - avatar