Skip to content Skip to sidebar Skip to footer

Changing One Element In A List From String To Integer

I was looking at this post, but I don't have the privilege to add a comment. My question is: > results = [int(i) for i in results] >>> results = ['1', '2', '3'] >

Solution 1:

Just simply write:

results[1] = int(results[1])

To change first element:

results[0] = int(results[0]) #because of 0 based indexing

Generally :

results[index] = int(results[index])

Post a Comment for "Changing One Element In A List From String To Integer"