Advertisement
SimeonTs

SUPyF Lists - 04. Rotate List of Strings

Jun 15th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. """
  2. Lists
  3. Проверка: https://judge.softuni.bg/Contests/Practice/Index/924#3
  4.  
  5. 04. Rotate List of Strings
  6.  
  7. Условие:
  8. Write a program to read a list of strings, rotate it to the right and print its rotated items.
  9.  
  10. Examples:
  11. Input           Output
  12. a b c d e       e a b c d
  13. soft uni hi     hi soft uni
  14. i r a b         b i r a
  15.  
  16. Hints:
  17. -You can store the rotated list in a second list alongside the first one
  18. """
  19.  
  20. # This will take all the added strings on one line divided by space and it will add them i a new list one by one:
  21. strings = [str(item) for item in input().split(" ")]
  22. # Next. We will create a new list called rotated_strings and its default items are the same as on the strings list.
  23. # But we will use the -1: and :-1 to remove and move the items by 1 to the right.
  24. rotated_strings = strings[-1:] + strings[:-1]
  25. # And finally we will use a For Loop to print each item one by one, and print it on one line with blank space in between
  26. for item in rotated_strings:
  27.     print(item, end=" ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement