6

If I am given an input of 1 2 3 4 5, what is the standard method of splitting such input and maybe add 1 to each integer?

I'm thinking something along the lines of splitting the input list and map each to an integer.

1
  • What do you want the result as ? List? Commented Sep 22, 2015 at 4:31

1 Answer 1

9

You may use list comprehension.

s = "1 2 3 4 5"
print [int(i)+1 for i in s.split()]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.