N
N
Nikolai Sidorenko2014-12-21 23:31:17
Python
Nikolai Sidorenko, 2014-12-21 23:31:17

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:
d1c615e4fb814076ae21d8e4428b35cd.JPG
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

Now everything worked out here, but pop from the z array erases

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2014-12-22
@NSidorov

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

And the result:
[
[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 question

Ask a Question

731 491 924 answers to any question