How to convert numeric string to integers in list with strings and numbers using Python

1 Answer

0 votes
lst = ["2", "99", "java", "34", "php", "7", "python", "c", "89"] 

lst = [int(ele) if ele.isdigit() else ele for ele in lst] 
 
print(lst)
  
       
      
'''
run:
 
[2, 99, 'java', 34, 'php', 7, 'python', 'c', 89]
      
'''

 



answered Apr 14, 2020 by avibootz

Related questions

...