Jun-11-2018, 11:57 PM
Or you could use the following which will allow mixed numbers and strings:
>>> mylist = ['1', '4', '6', '8', 'hello', '7'] >>> newlist = [int(item) if item.isdigit() else item for item in mylist] >>> newlist [1, 4, 6, 8, 'hello', 7] >>>