How to convert only numeric string to integers in a list with Python

1 Answer

0 votes
lst = ["python", "763", "c#", "99", "java", "018"] 

lst = [int(i) if i.isdigit() else i for i in lst] 
  
print(lst) 



'''
run:

['python', 763, 'c#', 99, 'java', 18]

'''

 



answered Dec 25, 2019 by avibootz
...