1
1
# fmt: off
2
2
def 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
+ """
3
12
return a + b
4
13
5
14
6
15
def 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
+
7
26
cursor = db .cursor ()
8
27
cursor .execute (query )
9
28
return cursor .fetchall ()
10
29
11
30
12
31
def 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
+ """
13
42
if key_map (item1 ) < key_map (item2 ):
14
43
return - 1
15
44
elif key_map (item1 ) > key_map (item2 ):
@@ -21,4 +50,12 @@ def compare(key_map, item1, item2):
21
50
def random_alphabets (
22
51
length : int
23
52
):
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
+ """
24
61
return '' .join (random .choices (string .ascii_letters , k = length ))
0 commit comments