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

2
  • Welcome to StackOverflow. Please make sure to take the tour and learn How to Ask. You are supposed to show how you tried to resolve it by yourself, and where you got stuck. Commented Oct 15, 2022 at 18:26
  • Does this answer your question? Efficient way to rotate a list in python Commented Oct 15, 2022 at 18:27

1 Answer 1

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]]
Sign up to request clarification or add additional context in comments.

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.