0

(in Python) inputs a list and outputs a square grid of values of that list in which each value only appears once in each column and row. each row is the one above it but last item is moved to the front. answer is list of lists, sub-list is a row of the square

grid([1, 2, 3, 4]) -> [[1, 2, 3, 4], [4, 1, 2, 3], [3, 4, 1, 2], [2, 3, 4, 1]]

which corresponds to:

1234 4123 3412 2341

dl br
  • 9
  • 1
  • Welcome to StackOverflow. Please make sure to take the [tour] and learn [ask]. You are supposed to show how you tried to resolve it by yourself, and where you got stuck. – Rodrigo Rodrigues Oct 15 '22 at 18:26
  • Does this answer your question? [Efficient way to rotate a list in python](https://stackoverflow.com/questions/2150108/efficient-way-to-rotate-a-list-in-python) – Rodrigo Rodrigues Oct 15 '22 at 18:27

1 Answers1

1

please use this command:

x = [1, 2, 3, 4]
[x[-i:]+x[:-i] for i in range(len(x))]

output:

[[1, 2, 3, 4], [4, 1, 2, 3], [3, 4, 1, 2], [2, 3, 4, 1]]