11# fmt: off
22def a_plus_b (a , b ):
3+ """Adds two numbers together.
4+
5+ Args:
6+ a (int or float): The first number to be added.
7+ b (int or float): The second number to be added.
8+
9+ Returns:
10+ int or float: The sum of the two numbers.
11+ """
312 return a + b
413
514
615def sqlite (db , query ):
16+ """Executes a given SQL query on a SQLite database and returns the results.
17+
18+ Args:
19+ db (sqlite3.Connection): A SQLite database connection object.
20+ query (str): The SQL query to be executed on the database.
21+
22+ Returns:
23+ list: A list of tuples containing the results of the query.
24+ """
25+
726 cursor = db .cursor ()
827 cursor .execute (query )
928 return cursor .fetchall ()
1029
1130
1231def compare (key_map , item1 , item2 ):
32+ """Compares two items based on a key mapping function and determines their order.
33+
34+ Args:
35+ key_map (function): A function that extracts a comparison key from each item.
36+ item1 (any): The first item to compare.
37+ item2 (any): The second item to compare.
38+
39+ Returns:
40+ int: -1 if item1 is less than item2, 1 if item1 is greater than item2, and 0 if they are equal.
41+ """
1342 if key_map (item1 ) < key_map (item2 ):
1443 return - 1
1544 elif key_map (item1 ) > key_map (item2 ):
@@ -21,4 +50,12 @@ def compare(key_map, item1, item2):
2150def random_alphabets (
2251 length : int
2352):
53+ """Generates a random string of alphabets.
54+
55+ Args:
56+ length (int): The desired length of the output string.
57+
58+ Returns:
59+ str: A randomly generated string consisting of ASCII alphabets (both lower and uppercase) of the specified length.
60+ """
2461 return '' .join (random .choices (string .ascii_letters , k = length ))
0 commit comments