1

For example:

I have an array number like

n = int(input().strip())           # 4
arr = map(int,input().strip().split(' ')) #2 4 3 1
print(arr[::-1])

inputs:

4 
2 4 3 1 

My output is [1,3,4,2]

But actual output must be 1 3 4 2

How do I implement this using python 3?

3
  • 2
    You question isn't about reversing a list, it's about providing a string output for a list. Commented Mar 17, 2017 at 14:55
  • 2
    just print(*arr[::-1]), as chepner said, it's the outputting that your question's about. Commented Mar 17, 2017 at 14:56
  • Also, the output of map isn't sliceable in Python 3, so your code doesn't produce the output you claim it does. Commented Mar 17, 2017 at 14:59

2 Answers 2

1

You could re-join the list to a string:

print(" ".join([str(x) for x in arr]))
Sign up to request clarification or add additional context in comments.

Comments

0

you can just unpack list using * operator

>>> arr = [*range(5)]
>>> print(*arr)
0 1 2 3 4

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.