A Quick guide to TkinterIntro tkinter is one of the more popular Python GUI libraries. 馃憠 When you start a tkinter project, you get some boilerplate, or starter code. import tkinter as tk window = tk.Tk() window.title("Hello World") # Sets the name of the window in the bo...Jul 27, 2023路5 min read
Zip Function in PythonCreates a list of elements, grouped based on the position in the original lists. Use max combined with a list comprehension to get the length of the longest list in the arguments. Loops for max_length times grouping elements. If lengths of lists vary...Jun 30, 2023路1 min read
Chunk Function in PythonChunks a list into smaller lists of a specified size. Use range to create a list of desired size. Then use map on this list and fill it with splices of lst. from math import ceil def chunk(lst, size): return list( map(lambda x: lst[x * ...Jun 29, 2023路1 min read
Shuffle Function in PythonRandomizes the order of the values of a list, returning a new list. Uses the Fisher-Yates algorithm to reorder the elements of the list. from copy import deepcopy from random import randint def shuffle(lst): temp_lst = deepcopy(lst) m = len...Jun 28, 2023路1 min read
Bubble sort in pythonBubble_sort uses the technique of comparing and swapping def bubble_sort(lst): for passnum in range(len(lst) - 1, 0, -1): for i in range(passnum): if lst[i] > lst[i + 1]: temp = lst[i] lst[i] =...Jun 27, 2023路1 min read
Compact functionRemoves falsey values from a list. Use filter() to filter out falsey values (False, None, 0, and ""). def compact(lst): return list(filter(bool, lst)) Here are the input and output: compact([0, 1, False, 2, '', 3, 'a', 's', 34]) # [ 1, 2, 3, 'a'...Jun 26, 2023路1 min read
LCM function in pythonReturns the least common multiple of two or more numbers. Use the greatest common divisor (GCD) formula and the fact that lcm(x,y) = x * y / gcd(x,y) to determine the least common multiple. The GCD formula uses recursion. Uses reduce function from th...Jun 25, 2023路1 min read