Loading...
More Python Posts
"""Take screenshots at x interval - make a movie of doings on a computer."""import timefrom datetime import datetimeimport ffmpegimport pyautoguiwhile True:epoch_time = int(time.time())today = datetime.now().strftime("%Y_%m_%d")filename = str(epoch_time) + ".png"print("taking screenshot: {0}".format(filename))myScreenshot = pyautogui.screenshot()myScreenshot.save(today + "/" + filename)time.sleep(5)## and then tie it together with: https://github.com/kkroening/ffmpeg-python/blob/master/examples/README.md#assemble-video-from-sequence-of-frames#"""import ffmpeg(ffmpeg.input('./2021_01_22/*.png', pattern_type='glob', framerate=25).filter('deflicker', mode='pm', size=10).filter('scale', size='hd1080', force_original_aspect_ratio='increase').output('movie.mp4', crf=20, preset='slower', movflags='faststart', pix_fmt='yuv420p').run())"""
from statistics import median, mean, modedef print_stats(array):print(array)print("median =", median(array))print("mean =", mean(array))print("mode =", mode(array))print()print_stats([1, 2, 3, 3, 4])print_stats([1, 2, 3, 3])
def print_x_pattern(size):i,j = 0,size - 1while j >= 0 and i < size:initial_spaces = ' '*min(i,j)middle_spaces = ' '*(abs(i - j) - 1)final_spaces = ' '*(size - 1 - max(i,j))if j == i:print(initial_spaces + '*' + final_spaces)else:print(initial_spaces + '*' + middle_spaces + '*' + final_spaces)i += 1j -= 1print_x_pattern(7)
# function which return reverse of a stringdef isPalindrome(s):return s == s[::-1]# Driver codes = "malayalam"ans = isPalindrome(s)if ans:print("Yes")else:print("No")
def calculate_values():value1 = 10value2 = 20return value1, value2result1, result2 = calculate_values()print("Result 1:", result1)print("Result 2:", result2)
from collections import defaultdictdef combine_values(*dicts):res = defaultdict(list)for d in dicts:for key in d:res[key].append(d[key])return dict(res)d1 = {'a': 1, 'b': 'foo', 'c': 400}d2 = {'a': 3, 'b': 200, 'd': 400}combine_values(d1, d2) # {'a': [1, 3], 'b': ['foo', 200], 'c': [400], 'd': [400]}