/ Published in: Python
                    
                                        
arr[::-1] does a list slice to reverse the array
str(x) for x in arr[::-1] casts the ints in the array as strings
map(str, arr[::-1]) does the same thing by using map to cast the ints
" ".join() joins the resulting strings with a space
                str(x) for x in arr[::-1] casts the ints in the array as strings
map(str, arr[::-1]) does the same thing by using map to cast the ints
" ".join() joins the resulting strings with a space
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
#!/bin/python3
import sys
n = int(input().strip())
arr = [int(arr_temp) for arr_temp in input().strip().split(' ')]
print(" ".join(str(x) for x in arr[::-1]))
print(" ".join(map(str, arr[::-1]))) # or
print(' '.join(map(str, reversed(arr)))) # or
Comments
 Subscribe to comments
                    Subscribe to comments
                
                