for m, (r, e) in enumerate(zip(revenue, expenses), 1):
print(f'Profit for month {m} = {r-e}')
from functools import reduce
from operator import mul
numbers = input('Введите 3 числа через пробел: ').split()
try:
numbers = list(map(int, numbers))
except ValueError:
print('Обнаружен недопустимый символ!')
else:
if len(numbers) == 3:
print('Результат перемножения чисел:', reduce(mul, numbers))
else:
print('Введено неверное количество чисел!')
import psutil
for proc in psutil.process_iter():
try:
if proc.name() == 'notepad.exe':
print(proc.exe())
break
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
C:\Windows\System32\notepad.exe
import re
import pandas as pd
from io import StringIO
srv_data = "A[1]=[1765540,14,2799,4790,'Ts','MSC','2019,8,7,21,00,00',-1,3,2,1,2,1,1,1,2,'20','13','','',82,'','',8,0];"\
"A[2]=[1706041,83,4134,19230,'3DF','rSC','2019,8,7,21,00,00',-1,3,1,2,0,0,0,0,0,'14','8','','',66,'','',0,0];"
csv_data = '\n'.join(re.findall('=\[(.+?)\];', srv_data))
# Вариант без регулярок:
# csv_data = '\n'.join(line.split('=')[1].strip('[]') for line in srv_data.split(';') if line)
df = pd.read_csv(StringIO(csv_data), quotechar="'", header=None)
import pandas as pd
data = "A[1]=[1765540,14,2799,4790,'Ts','MSC','2019,8,7,21,00,00',-1,3,2,1,2,1,1,1,2,'20','13','','',82,'','',8,0];"\
"A[2]=[1706041,83,4134,19230,'3DF','rSC','2019,8,7,21,00,00',-1,3,1,2,0,0,0,0,0,'14','8','','',66,'','',0,0];"
A = {}
exec(data) # Потенциально опасная операция, т.к. в ответе сервера может быть вредоносный код
pd.DataFrame(A.values())
from functools import reduce
from pathlib import PurePosixPath
paths = [
'E:/folder/maps',
'E:/1/2/3',
'E:/folder/new',
'E:/folder/maps/2',
'D:/papka/echepapka',
'E:/1/path/dir',
]
tree = {}
for path in map(PurePosixPath, paths):
reduce(lambda node, part: node.setdefault(part, {}), path.parts, tree)
{'E:': {'folder': {'maps': {'2': {}}, 'new': {}},
'1': {'2': {'3': {}}, 'path': {'dir': {}}}},
'D:': {'papka': {'echepapka': {}}}}
from pathlib import Path
path = Path('Data') / 'data.txt'
import cv2
video1 = cv2.VideoCapture('video1.mp4')
video1_width = video1.get(cv2.CAP_PROP_FRAME_WIDTH)
video1_height = video1.get(cv2.CAP_PROP_FRAME_HEIGHT)
video1_fps = video1.get(cv2.CAP_PROP_FPS)
video2 = cv2.VideoCapture('video2.mp4')
writer = cv2.VideoWriter('video3.mp4', cv2.VideoWriter_fourcc(*'MP4V'), video1_fps, (video1_width, video1_height))
writer.set(cv2.VIDEOWRITER_PROP_QUALITY, 100)
while True:
ret, frame = video2.read()
if not ret:
break
frame = cv2.resize(frame, (video1_width, video1_height))
writer.write(frame)
video1.release()
video2.release()
writer.release()
id999 = True
request = input('Введите число')
print(eval(f'id{request}'))
>>> lst = list(range(10))
>>> lst
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(zip(*[iter(lst)]*3))
[(0, 1, 2), (3, 4, 5), (6, 7, 8)]
>>> list(zip(*[iter(lst)]*2))
[(0, 1), (2, 3), (4, 5), (6, 7), (8, 9)]
>>> from itertools import zip_longest
>>> list(zip_longest(*[iter(lst)]*3, fillvalue=None))
[(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, None, None)]
import numpy as np
np.array_split(lst, 3)