Reputation: 1
List=["2","10","15","23","exit"]
# Output required
List_new = [2,10,15,23]
Upvotes: 0
Views: 49
Reputation: 1
You can use .isdigit()
List_given =["2","10","15","23","exit"]
def new_list(List_given):
List_new = []
for item in list(List_given):
if item.isdigit():
List_new.append(item)
return List_new
new_list(List_given)
Upvotes: 0
Reputation: 7268
You can use isnumeric
>>> List=["2","10","15","23","exit"]
>>> output = [int(i) for i in List if i.isnumeric()]
>>> print(output)
[2, 10, 15, 23]
Upvotes: 0