Advertisement
SimeonTs

SUPyF Lists - Extra 03. Reverse Array In-place

Jun 15th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. """
  2. Lists
  3. Check your answer: https://judge.softuni.bg/Contests/Practice/Index/426#2
  4.  
  5. 03. Reverse Array In-place
  6.  
  7. Problem:
  8. Read a list of integers on the first line of the console. After that, reverse the list in-place
  9. (as in, don’t create a new collection to hold the result, reverse it using only the original list).
  10. After you are done, print the reversed list on the console.
  11. Note: You are not allowed to iterate over the list backwards and just print it,
  12. Examples
  13. Input               Output
  14. 1 2 3 4 5           5 4 3 2 1
  15. 1 4 2 7 6 1 1       1 1 6 7 2 4 1
  16. 11 52 43 12 1 6     6 1 12 43 52 11
  17. """
  18.  
  19. nums = [int(item) for item in input().split(" ")]
  20.  
  21. nums.reverse()
  22.  
  23. for num in nums:
  24.     print(num, end=" ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement