from itertools import permutations
# словарь существующих слов
dictionary = [
'пена',
]
for im in permutations('енап', 4):
word = ''.join(im)
print(word, word in dictionary)
енап False
енпа False
еанп False
еапн False
епна False
епан False
неап False
непа False
наеп False
напе False
нпеа False
нпае False
аенп False
аепн False
анеп False
анпе False
апен False
апне False
пена True
пеан False
пнеа False
пнае False
паен False
пане False
def check_it(word1:str, word2:str) -> bool:
if len(word1) != len(word2):
return False
return sorted(word1) == sorted(word2)
for word in dictionary:
if check_it(word, 'енап'):
print(word)
епан
напе
пане
пеан
пена
@login_required(redirect_field_name='my_redirect_field')
def delete(request, img_id):
img = get_object_or_404(Image, id=img_id)
if img.author != request.user:
return ... # мы не автор объекта - на выход...
# ... дальше логика работы с объектом
img.delete()
return redirect('index')
везде ответы максимально размытые, "скрипты для игр",
import io
import pandas as pd
data = cvs_data = io.StringIO('''Date, 1, 2, 3, 4
2010-02-04, 213.429998, 214.499996, 212.38000099999996, 214.009998
2010-03-05, 214.599998, 215.589994, 213.249994, 214.379993
2010-04-06, 214.379993, 215.23, 210.750004, 210.969995
2010-05-07, 211.75, 212.000006, 209.050005, 210.58
2010-06-08, 210.299994, 212.000006, 209.06000500000002, 211.98000499999998''')
df = pd.read_csv(data, sep=",")
df['Date'] = pd.to_datetime(df.Date)
print(df[df['Date'] > datetime.datetime(2010, 5, 1)])
Date 1 2 3 4
3 2010-05-07 211.750000 212.000006 209.050005 210.580000
4 2010-06-08 210.299994 212.000006 209.060005 211.980005
import random
import numpy as np
RANGE = 1000
data = np.ones(RANGE)
data[random.randint(0, RANGE)] = random.choice([1, 42])
data = list(data)
def check_ones1():
result = True
for im in data:
if im != 1:
result = False
break
return result
def check_ones2():
return all(map(lambda x:x==1, data))
def check_ones3():
return data.count(1) == len(data)
assert check_ones1() == check_ones2() == check_ones3()
print(check_ones1())
# False
%timeit check_ones1()
69.6 µs ± 779 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
%timeit check_ones2()
94 µs ± 936 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
%timeit check_ones3()
87.7 µs ± 633 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
# True
%timeit check_ones1()
93.5 µs ± 776 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
%timeit check_ones2()
124 µs ± 374 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
%timeit check_ones3()
86.9 µs ± 566 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('admin', 'admin@myproject.com', 'password')" | python manage.py shell
...
username = os.getenv('ADMIN_USER')
password = os.getenv('ADMIN_PASSWORD')
user = get_user_model().objects.filter(username=username).first()
if not user:
get_user_model().objects.create_superuser(username=username, password=password, email='')