Answer the question
In order to leave comments, you need to log in
How to create a clockwise dictionary using python?
While it sounds incomprehensible)
But listen:
There is a round table at which n people, each asks a question to another person through 2n-1 sitting between them (it turns out in turn to each, after one, you can’t yourself).
I need to create a dictionary of type, n = 5:
Here is my futile attempt:
p = list(range(1,n+1))
chet = dict(zip(range(3,n+1,2),range(1,n+1)))
ost = []
z = []
f = 0
while f != chet[n]:
for i in [1,2]:
ost.append(p.pop(0))
if i == 2:
p = p + ost
print(p)
z.append(p)
print(z)
ost = []
f += 1
Answer the question
In order to leave comments, you need to log in
And indeed:
n = 5
s = list(range(1, n+1))
out = []
for x in range(1, len(s) + 1):
for y in range(1, len(s) + 1):
out.append(s[-y:] + s[:-y])
print out
[
[5, 1, 2, 3, 4],
[4, 5, 1, 2, 3],
[3, 4, 5, 1, 2],
[2, 3, 4, 5, 1],
[1, 2, 3, 4, 5],
[5, 1, 2, 3, 4],
[4, 5, 1, 2, 3],
[3, 4, 5, 1, 2],
[2, 3, 4, 5, 1],
[1, 2, 3, 4, 5],
[5, 1, 2, 3, 4],
[4, 5, 1, 2, 3],
[3, 4, 5, 1, 2],
[2, 3, 4, 5, 1],
[1, 2, 3, 4, 5],
[5, 1, 2, 3, 4],
[4, 5, 1, 2, 3],
[3, 4, 5, 1, 2],
[2, 3, 4, 5, 1],
[1, 2, 3, 4, 5],
[5, 1, 2, 3, 4],
[4, 5, 1, 2, 3],
[3, 4, 5, 1, 2],
[2, 3, 4, 5, 1],
[1, 2, 3, 4, 5]]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question