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]

1 Answer 1

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])
Sign up to request clarification or add additional context in comments.

2 Comments

It said i can accept the answer in 7 minutes. im just waiting for those 7 minutes
Accepted! Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.