0

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"]

>>> results = [int(i) for i in results]

>>> results

[1, 2, 3]

What if I need to change only the first element in the list, how can I do that? By indexing? so something like:

> results=[int(1) for i in results]
Netwave
  • 40,134
  • 6
  • 50
  • 93
kay
  • 13
  • 5

1 Answers1

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])
Taohidul Islam
  • 5,246
  • 3
  • 26
  • 39