In [1]: from datetime import datetime
In [2]: date_inp = 'Mon, 02 Mar 2020 13:30:00 +0300'
In [3]: date_obj = datetime.strptime(date_inp, '%a, %d %b %Y %H:%M:%S %z')
In [4]: date_outp = date_obj.strftime('%Y-%m-%d')
In [5]: date_outp
Out[5]: '2020-03-02'
Difficulties
не словарь с названиями сложности, а множество, вот пример:In [1]: foo = {'foo': {'1', '2', '3', '4', '5'}}
In [2]: foo
Out[2]: {'foo': {'1', '2', '3', '4', '5'}}
In [3]: type(foo['foo'])
Out[3]: set
"Difficulties": [
"Легкий",
"Нормальный",
"Трудный",
"Невозможный"
]
In [1]: foo = {"Difficulties": [
...: "Легкий",
...: "Нормальный",
...: "Трудный",
...: "Невозможный"
...: ]}
In [2]: for f in foo['Difficulties']:
...: print(f)
...:
Легкий
Нормальный
Трудный
Невозможный
from random import randint, randrange
from pprint import pprint
from os import system
from copy import deepcopy
class CellLife:
def __init__(self, x = None, y = None):
self.x, self.y = [randrange(10, 25) for _ in range(2) if x is None or y is None]
self.field = [[randint(0, 1) for _ in range(self.x)] for _ in range(self.y)]
self.field_state = None
def environment(self, row, index):
left_neighbors = row[:index][-8:]
right_neighbors = row[index:][1:9:]
while len(left_neighbors + right_neighbors) > 8:
if left_neighbors < right_neighbors:
right_neighbors = right_neighbors[:-1]
else:
left_neighbors = left_neighbors[1:]
return left_neighbors + right_neighbors
def dead_or_alive(self, env, cell):
state = None
if cell == 1:
if env.count(1) < 2 or env.count(1) > 3:
state = False
elif env.count(1) in (2, 3):
state = True
else:
if env.count(1) == 3:
state = True
return state
def start_survival(self):
while self.field_state != self.field:
self.field_state = deepcopy(self.field)
for r_index, row in enumerate(self.field):
for c_index, cell in enumerate(row):
env = self.environment(row, c_index)
state = self.dead_or_alive(env, cell)
if state is not None:
if state is True:
self.field[r_index][c_index] = 1
else:
self.field[r_index][c_index] = 0
system('cls')
pprint(self.field)
cell_field = CellLife()
cell_field.start_survival()
import time
from threading import Thread
stop = False
def some_thread():
while not stop:
print(stop)
time.sleep(0.5)
if __name__ == "__main__":
some_task = Thread(target=some_thread)
some_task.start()
time.sleep(2)
stop = True
some_task.join()