7

I tried to change from Python 2.7 to 3.3.1

I want to input

1 2 3 4

and output in

[1,2,3,4]

In 2.7 I can use

score = map(int,raw_input().split())

What should I use in Python 3.x?

0

2 Answers 2

28

Use input() in Python 3. raw_input has been renamed to input in Python 3 . And map now returns an iterator instead of list.

score = [int(x) for x in input().split()]

or :

score = list(map(int, input().split()))
Sign up to request clarification or add additional context in comments.

Comments

1

As a general rule, you can use the 2to3 tool that ships with Python to at least point you in the right direction as far as porting goes:

$ echo "score = map(int, raw_input().split())" | 2to3 - 2>/dev/null
--- <stdin> (original)
+++ <stdin> (refactored)
@@ -1,1 +1,1 @@
-score = map(int, raw_input().split())
+score = list(map(int, input().split()))

The output isn't necessarily idiomatic (a list comprehension would make more sense here), but it will provide a decent starting point.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.