'''
Created on 3 окт. 2016 г.
@author: leah
'''
from collections import deque
k = 10
mas= [[None]*k for i in range(k)]
point = (0,0)
route = deque([lambda x,y: (x+1,y), lambda x,y: (x,y+1), lambda x,y: (x-1,y), lambda x,y: (x,y-1)])
count = 0
while(True):
x,y = point # current point
if mas[x][y] == None:
mas[x][y] = count
count = count +1
else:
break # done
_x,_y = route[0](*point) # next point
if (_x >= k) or (_y >= k) or (_x < 0) or (_y < 0): # check arrays overflow
route.rotate(-1) #change direction
elif mas[_x][_y] != None:
route.rotate(-1) #change direction
point = route[0](*point)
for i in mas:
print(" ".join(str(i)))
[ 0 , 3 5 , 3 4 , 3 3 , 3 2 , 3 1 , 3 0 , 2 9 , 2 8 , 2 7 ]
[ 1 , 3 6 , 6 3 , 6 2 , 6 1 , 6 0 , 5 9 , 5 8 , 5 7 , 2 6 ]
[ 2 , 3 7 , 6 4 , 8 3 , 8 2 , 8 1 , 8 0 , 7 9 , 5 6 , 2 5 ]
[ 3 , 3 8 , 6 5 , 8 4 , 9 5 , 9 4 , 9 3 , 7 8 , 5 5 , 2 4 ]
[ 4 , 3 9 , 6 6 , 8 5 , 9 6 , 9 9 , 9 2 , 7 7 , 5 4 , 2 3 ]
[ 5 , 4 0 , 6 7 , 8 6 , 9 7 , 9 8 , 9 1 , 7 6 , 5 3 , 2 2 ]
[ 6 , 4 1 , 6 8 , 8 7 , 8 8 , 8 9 , 9 0 , 7 5 , 5 2 , 2 1 ]
[ 7 , 4 2 , 6 9 , 7 0 , 7 1 , 7 2 , 7 3 , 7 4 , 5 1 , 2 0 ]
[ 8 , 4 3 , 4 4 , 4 5 , 4 6 , 4 7 , 4 8 , 4 9 , 5 0 , 1 9 ]
[ 9 , 1 0 , 1 1 , 1 2 , 1 3 , 1 4 , 1 5 , 1 6 , 1 7 , 1 8 ]
import sys
from PyQt4.QtCore import QTimer
from PyQt4.QtGui import QApplication
app = QApplication(sys.argv)
app.setQuitOnLastWindowClosed(False)
def tick():
print 'tick'
timer = QTimer()
timer.timeout.connect(tick)
timer.start(1000)
# run event loop so python doesn't exit
app.exec_()
class objdict(dict):
def __getattr__(self, name):
if name in self:
return self[name]
else:
raise AttributeError("No such attribute: " + name)
def __setattr__(self, name, value):
self[name] = value
def __delattr__(self, name):
if name in self:
del self[name]
else:
raise AttributeError("No such attribute: " + name)
good_fileds = set(["actors", "composers", "counties", "directors", "genres", "id", "producers", "profit_russia",
"profit_usa", "profit_world", "rating", "scenarios", "title", "title_original", "trailers", "year"])
keys = good_fileds.intersection(movie.__dict__)
result = objdict({k: movie.__dict__.get(k) for k in keys})
result.rating
result.actors