source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
python_sharegpt_23k
2,506
Write a Python function to count the number of times a given character appears in a string without using any built-in functions or methods that directly count the occurrences of the character. The solution must have a time complexity of O(n), where n is the length of the string, and a space complexity of O(1). The cod...
Here is the Python code to solve the given problem in the markdown block: ```python def count_character(string: str, char: str) -> int: """ Counts the number of times a given character appears in a string without using any built-in functions or methods. Args: string (str): The string in which to co...
python_sharegpt_23k
2,513
Write a Python function to determine if one positive integer is evenly divisible by another positive integer without using the modulus operator (`%`). The function should also handle the case where the divisor is zero. The code should start with: ```python def is_evenly_divisible(num1: int, num2: int) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_evenly_divisible(num1: int, num2: int) -> bool: """ Determines if one positive integer is evenly divisible by another positive integer without using the modulus operator. Args: num1 (int): The dividend, a pos...
python_sharegpt_23k
2,517
Write a Python function to find prime numbers within a given range `[start, end]` that are not divisible by both 2 and 3. The function should validate that the inputs are positive integers greater than zero. Additionally, the function should return the prime numbers in ascending order and in a comma-separated string fo...
Here is the Python code to solve the given problem in the markdown block: ```python def find_prime_numbers(start: int, end: int) -> str: """ Finds prime numbers within the given range [start, end] that are not divisible by both 2 and 3. Returns the prime numbers in ascending order and in a comma-separated s...
python_sharegpt_23k
2,521
Write a Python function to calculate the total sum of all even numbers that are divisible by 4 in a given list. If there are no such numbers in the list, return -1. The function should use an accumulator pattern to achieve this. The code should start with: ```python from typing import List def sum_even_divisible_by_4...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_even_divisible_by_4(numbers: List[int]) -> int: """ Calculate the total sum of all even numbers that are divisible by 4 in a given list. If no such numbers are found, return -1. Args: ...
python_sharegpt_23k
2,523
Write a Python function to implement an optimized version of the bubble sort algorithm that improves both time complexity and space complexity. The function should also include a mechanism to detect if the array is already sorted and terminate early to avoid unnecessary iterations. The code should start with: ```python...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def optimized_bubble_sort(arr: List[int]) -> List[int]: """ Sorts the input list using an optimized bubble sort algorithm. The algorithm improves upon the traditional bubble sort by: 1. Terminat...
python_sharegpt_23k
2,525
Write a Python function to sort a given dictionary of strings in reverse alphabetical order, while ignoring case sensitivity. The function should return a new dictionary with the sorted key-value pairs. The code should start with: ```python from typing import Dict def sort_dict_reverse_alphabetical(my_dict: Dict[str,...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_reverse_alphabetical(my_dict: Dict[str, str]) -> Dict[str, str]: """ Sorts a given dictionary of strings in reverse alphabetical order, ignoring case sensitivity. Args: my_dict...
python_sharegpt_23k
2,528
Write a Python function to find all prime numbers between 0 and a given number `n` (where `n` can be up to 1 billion) using a while loop. The solution should have a time complexity of O(sqrt(n)) and a space complexity of O(1). Additionally, implement a separate function to check if a given number is a palindrome. The p...
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime(n: int) -> bool: """ Check if a given number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. """ ...
python_sharegpt_23k
2,529
Write a Python function to extract prime numbers from a given list of integers, ensuring that duplicates are removed before checking for prime numbers. The function should have a time complexity of O(n^2) and a space complexity of O(n). The code should start with: ```python from typing import List def get_prime_numbe...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_prime_numbers(nums: List[int]) -> List[int]: """ Extracts prime numbers from a given list of integers, removing duplicates first. Args: nums (List[int]): The list of integers from wh...
python_sharegpt_23k
2,530
Write a Python function called `square_odds` that takes in a list of integers and returns a new list with the squared value of each odd number. If the element is not an odd number, skip it and do not include it in the new list. Additionally, the function should keep track of the sum of all the squared odd numbers and r...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def square_odds(nums: List[int]) -> Tuple[List[int], int]: """ Returns a new list with the squared value of each odd number from the input list, and the sum of all squared odd numbers. Ar...
python_sharegpt_23k
2,531
Write a Python function to generate a list of all prime numbers from 0 to a given upper limit `n` using list comprehension. Additionally, implement a helper function to check if a number is prime. The generated list should be sorted in ascending order. The code should start with: ```python from typing import List def...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(num: int) -> bool: """ Check if a given number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime, False other...
python_sharegpt_23k
2,536
Write a Python function to calculate the mean of a list of numbers without using any built-in functions or libraries for calculating the mean. The function should handle lists with duplicate numbers and ensure that the solution has a time complexity of O(n). The code should start with: ```python from typing import Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_mean(numbers: List[int]) -> float: """ Calculate the mean of a list of numbers without using any built-in functions or libraries. Args: numbers (List[int]): The list of numbers...
python_sharegpt_23k
2,537
Write a Python function to find the maximum number in a given list of integers without using any built-in functions or methods to find the maximum value. The function should implement its own algorithm to solve this problem with a time complexity of O(n), where n is the length of the list. Additionally, the function sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_maximum_number(lst: List[int]) -> int or str: """ Finds the maximum number in a given list of integers without using built-in functions or methods. Args: lst (List[int]): The list o...
python_sharegpt_23k
2,544
Write a Python function to print all the prime numbers from a given list in ascending order. The function should have a time complexity of O(n) and should not use any built-in Python functions. Additionally, the function should only use a single loop and should not use any additional data structures or variables apart ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(n): """ Helper function to check if a number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. """ if n < 2: ...
python_sharegpt_23k
2,545
Write a Python function to process election results based on a list of votes. Each vote is represented as a tuple containing a candidate's name and the number of votes they received. The function should return a dictionary with the following details: - Each candidate's name as a key, and their vote count and percentage...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def process_election_results(votes: List[Tuple[str, int]]) -> Dict[str, Dict[str, float]]: """ Process election results based on a list of votes. Args: votes (List[Tuple[str, in...
python_sharegpt_23k
2,546
Write a Python function to iterate over a list of numbers and compute their sum without using any built-in functions or operators for addition. Instead, use basic arithmetic operations such as subtraction, multiplication, and division. The list can contain both positive and negative integers, as well as floating-point ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def add_numbers(numbers: List[float]) -> Tuple[int, int]: """ Computes the sum of a list of numbers without using the addition operator. Instead, uses subtraction, multiplication, and division...
python_sharegpt_23k
2,547
Write a Python function to determine if a given string is a palindrome, considering only alphabetic characters and ignoring case. The function should handle strings with special characters and numbers by ignoring them. The function should have a time complexity of O(n) and should not use any built-in functions or libra...
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(string: str) -> bool: """ Determine if a given string is a palindrome, considering only alphabetic characters and ignoring case. Args: string (str): The input string to check for palindrome. R...
python_sharegpt_23k
2,558
Write a Python function to find the two elements in an integer array that have the maximum absolute difference. The function should return these two elements as a list. The solution should have a time complexity of O(n log n) and a space complexity of O(1), meaning it should use a constant amount of extra space regardl...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_difference_pair(A: List[int]) -> List[int]: """ Find the two elements in an integer array that have the maximum absolute difference. Args: A (List[int]): The input array of inte...
python_sharegpt_23k
2,564
Write a Python function that removes duplicate elements from a given list of integers, keeping only the first occurrence of each element, and returns the modified list in reverse order. The function should be implemented using only a single loop and without using any additional data structures (such as dictionaries or ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates_reverse(lst: List[int]) -> List[int]: """ Removes duplicate elements from the given list of integers, keeping only the first occurrence of each element, and returns the modified...
python_sharegpt_23k
2,565
Write a Python function to retrieve unique values from a list of integers and return them in descending order. The list may contain both positive and negative integers. The function should handle lists with lengths between 1 and 10^5, and each element can range from -10^9 to 10^9. The function should start with: ```pyt...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def retrieve_unique_descending(lst: List[int]) -> List[int]: """ Retrieve unique values from a list of integers and return them in descending order. Args: lst (List[int]): A list of integers...
python_sharegpt_23k
2,567
Write a Python function to remove all occurrences of a specified element from a given list, including any duplicates of that element. The function should also handle lists containing nested lists and remove the element and its duplicates from the nested lists as well. The function should have a time complexity of O(n) ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def remove_element_and_duplicates(lst: List[Any], element: Any) -> List[Any]: """ Remove all occurrences of a specified element from a given list, including any duplicates. The function also han...
python_sharegpt_23k
2,579
Implement a sorting algorithm that sorts an array of integers in ascending order without using any built-in sorting functions or libraries. The algorithm should have a time complexity of O(n log n) and use constant space complexity. The array will not contain any duplicate values. Additionally, provide a piece of erron...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers in ascending order using the merge sort algorithm. Args: arr (List[int]): The array of integers to be sorted. ...
python_sharegpt_23k
2,580
Write a Python function to find the most frequent item in a given list of integers. If there are multiple items with the same highest frequency, return the item that appears first in the list. The function should have a time complexity of O(n), where n is the length of the input list. Additionally, you are not allowed ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def most_frequent_item(lst: List[int]) -> int: """ Find the most frequent item in a list of integers. If there are multiple items with the same highest frequency, return the item that appears first i...
python_sharegpt_23k
2,581
Write a Python function to determine if a given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward, ignoring case, whitespace, and punctuation. The function should start with: ```python def is_palindrome(string: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(string: str) -> bool: """ Determine if the given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward, ignoring case,...
python_sharegpt_23k
2,586
Write a Python function that returns the first two characters of a given string. The function must have a time complexity of O(n) and must not use any built-in string manipulation functions or methods. Additionally, the function should be able to handle strings of any length, including very large strings. The code shou...
Here is the Python code to solve the given problem in the markdown block: ```python def get_first_two_chars(s: str) -> str: """ Returns the first two characters of the given string. Args: s (str): The input string from which to extract the first two characters. Returns: str: A string c...
python_sharegpt_23k
2,596
Write a Python function to reverse a given string without using any built-in string manipulation functions, methods, or data structures such as lists or arrays. The time complexity of your solution should be O(n) and the space complexity should be O(1). The function should start with: ```python def reverse_string(s: st...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses a given string without using any built-in string manipulation functions, methods, or data structures. Args: s (str): The input string to be reversed. Returns: ...
python_sharegpt_23k
2,599
Write a Python function to calculate the total price of a given list of items, including taxes. Each item in the list is represented by a dictionary with keys "name", "price", and "quantity". The tax rate is provided as a separate variable. The function should correctly handle the calculation of the total price and the...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def calculate_total_price(items: List[Dict[str, float]], tax_rate: float) -> float: """ Calculate the total price of a list of items, including taxes. Args: items (List[Dict[str, float...
python_sharegpt_23k
2,602
Write a Python function to flatten a two-dimensional array into a one-dimensional array, remove any duplicate elements, and sort the resulting array in ascending order. The function should adhere to the given time complexity requirement of O(n^2) and space complexity requirement of O(n). The code should start with: ``...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def flatten_and_sort_array(arr: List[List[int]]) -> List[int]: """ Flattens a two-dimensional array into a one-dimensional array, removes duplicate elements, and sorts the resulting array in ascending or...
python_sharegpt_23k
2,608
Write a Python function to sum up all the positive integers in a given dictionary, where the keys are strings and the values are either positive integers or nested dictionaries following the same format. The function should handle dictionaries with at least 10 key-value pairs and a maximum of 20 key-value pairs. The su...
Here is the Python code to solve the given problem in the markdown block: ```python def sum_positive_elements(dictionary: dict) -> int: """ Sum all positive integers in a dictionary, including those in nested dictionaries. Args: dictionary (dict): A dictionary where keys are strings and values are ...
python_sharegpt_23k
2,611
Write a Python function to combine two lists and return a new list containing only the unique elements from both lists, while preserving the original order of elements. The function should efficiently handle input lists with up to \(10^6\) elements and remove any duplicates within each list before combining them. The f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_unique_elements(list1: List[int], list2: List[int]) -> List[int]: """ Combines two lists and returns a new list containing only the unique elements from both lists, while preserving the origi...
python_sharegpt_23k
2,612
Write a Python function to sort a given array in descending order using a stable sorting algorithm with a time complexity of O(n^2). The function should remove any duplicate elements from the array before sorting. The relative order of equal elements should be preserved after sorting. The code should start with: ```pyt...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def stable_sort_descending(arr: List[int]) -> List[int]: """ Sorts the given array in descending order using a stable sorting algorithm with a time complexity of O(n^2). The function removes any dupl...
python_sharegpt_23k
2,618
Write a Python function to recursively count the occurrences of a specific string in a jagged array, but only in sub-arrays that have a length greater than a given threshold. The function should include at least two base cases and demonstrate the proper use of recursive calls. The jagged array is a list of lists, where...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_occurrences_in_jagged_array(arr: List[List[str]], target: str, lengthThreshold: int) -> int: """ Recursively count the occurrences of a specific string in a jagged array, but only in sub-arrays...
python_sharegpt_23k
2,621
Write a Python function to print all prime numbers between 1 and 100 without using any built-in functions or libraries for prime number generation or checking. You can only use basic arithmetic operations, loops, and conditional statements. Additionally, optimize your algorithm to minimize the number of operations requ...
Here is the Python code to solve the given problem in the markdown block: ```python def print_primes_up_to_100(): """ Prints all prime numbers between 1 and 100. This function uses basic arithmetic operations, loops, and conditional statements to determine and print prime numbers. It optimizes the prim...
python_sharegpt_23k
2,625
Write a Python function to count the number of occurrences of a given number in a list of numbers without using built-in functions or methods that directly count the occurrences. The input list may contain duplicates and negative numbers. The code should start with: ```python from typing import List def count_occurre...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_occurrences(numbers: List[int], number: int) -> int: """ Counts the number of occurrences of a given number in a list of numbers. Args: numbers (List[int]): The list of numbers to ...
python_sharegpt_23k
2,626
Write a Python function to find the maximum number in a given list of integers. The function should follow these steps: 1. Initialize a variable called `max_num` with the first element of the list. 2. Iterate through each element in the list starting from the second element. 3. For each element, check if it is greater ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_max_number(numbers: List[int]) -> int: """ Find the maximum number in a given list of integers. Args: numbers (List[int]): The list of integers from which to find the maximum number...
python_sharegpt_23k
2,629
Write a Python function to reverse a given string in-place using a stack, without using any additional data structures, and ensure that the function has a time complexity of O(n) and a space complexity of O(1), where n is the length of the string. The function should modify the input string directly. The code should s...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string_in_place(string: str) -> str: """ Reverses the given string in-place using a stack, without using any additional data structures. The function has a time complexity of O(n) and a space complexity of O(1), ...
python_sharegpt_23k
2,634
Write a Python function to count the number of distinct words in a given string, considering only alphabetic characters and ignoring case. The function should have a time complexity of O(n), where n is the length of the string. The function should not use any built-in Python functions or libraries for string manipulati...
Here is the Python code to solve the given problem in the markdown block: ```python def count_distinct_words(string: str) -> int: """ Counts the number of distinct words in a given string, considering only alphabetic characters and ignoring case. Args: string (str): The input string to count distin...
python_sharegpt_23k
2,637
Write a Python function to calculate the sum of all previous numbers up to the current iteration for a given range. The function should also print a comment before each iteration and introduce a logic error by mistakenly incrementing the value of `j` instead of `sum` in the inner for loop. The code should start with: `...
Here is the Python code to solve the given problem in the markdown block: ```python def calculate_sum_with_error(n: int) -> None: """ Calculate the sum of all previous numbers up to the current iteration for a given range. Introduce a logic error by mistakenly incrementing the value of 'j' instead of 'sum' ...
python_sharegpt_23k
2,639
Write a Python function to generate a list of all prime numbers up to a given positive integer `n` in descending order. The function should have a time complexity of O(n^2 log n) and a space complexity of O(n). The code should start with: ```python from typing import List def generate_primes_descending(n: int) -> List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Helper function to check if a number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, Fa...
python_sharegpt_23k
2,640
Write a Python function to compare two strings and determine if they are equal. The function should perform a case-sensitive comparison, consider whitespace characters, and ensure that the strings do not contain any leading or trailing whitespace characters. The strings must also not exceed a length of 100 characters a...
Here is the Python code to solve the given problem in the markdown block: ```python def compare_strings(string1: str, string2: str) -> bool: """ Compare two strings to determine if they are equal, considering the following constraints: - The strings must not contain any leading or trailing whitespace charac...
python_sharegpt_23k
2,644
Write a Python function to generate a multiplication table for a given positive integer `n`. The function should return a list of lists where each sublist represents a row in the multiplication table. Each row and column should represent a number from 1 to `n` (inclusive). The function should also validate that the inp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_multiplication_table(n: int) -> List[List[int]]: """ Generate a multiplication table for a given positive integer `n`. Args: n (int): The positive integer for which the multipli...
python_sharegpt_23k
2,652
Write a Python function to perform a linear search for a specific string "hello" in a given list of strings and return the indices of all occurrences of the string "hello" in the list. The function should have a time complexity of O(n) and utilize a recursive approach. The code should start with: ```python from typing...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_all_hello_indices(strings: List[str]) -> List[int]: """ Find all indices of the string "hello" in the given list of strings using a recursive approach. Args: strings (List[str]): Th...
python_sharegpt_23k
2,654
Write a Python function to subtract one matrix from another and store the result in a new matrix. The matrices will be of size `n x m`, where `n` is the number of rows and `m` is the number of columns. The elements of the matrices will be integers. The function should correctly handle the subtraction of matrix `B` from...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def subtract_matrices(A: List[List[int]], B: List[List[int]]) -> List[List[int]]: """ Subtract matrix B from matrix A and store the result in matrix C. Args: A (List[List[int]]): The first m...
python_sharegpt_23k
2,668
Write a Python function to find the length of the shortest subarray that sums up to a given target value `k`. If no such subarray exists, return `-1`. The function should efficiently handle the problem using a prefix sum and a hash map to store the indices of prefix sums. The code should start with: ```python from typ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_shortest_subarray_length(nums: List[int], k: int) -> int: """ Find the length of the shortest subarray that sums up to the given target value k. Args: nums (List[int]): The array of...
python_sharegpt_23k
2,670
Write a Python function to calculate the sum of all prime numbers in a given list of numbers. The function should handle cases where the list is empty, contains non-integer elements, or includes negative numbers. Non-integer and negative numbers should be ignored, and only non-negative prime integers should be consider...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. ...
python_sharegpt_23k
2,676
Write a Python function to determine the type of a given string `x` based on a predefined dictionary `type_dict`. If the string `x` matches one of the keys in the dictionary, the corresponding value should be returned. If the string `x` does not match any key, the function should return the string "unknown". The functi...
Here is the Python code to solve the given problem in the markdown block: ```python def find_type(x: str) -> str: """ Determines the type of the given string `x` based on a predefined dictionary. Args: x (str): The input string to determine the type of. Returns: str: The corresponding ...
python_sharegpt_23k
2,679
Write a Python function to sort the elements in an integer array in non-decreasing order using the merge sort algorithm. The function should use only constant space complexity and should not use any built-in sorting functions or libraries. The solution should have a time complexity of O(n log n) or better and should be...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts the elements in an integer array in non-decreasing order using the merge sort algorithm. Args: arr (List[int]): The array to be sorted....
python_sharegpt_23k
2,680
Write a Python function to replace all occurrences of a given `pattern` with the word "lessons" in a given `text`. The function should be case-insensitive and should preserve the original case of the letters in the replaced word "lessons". The function should not use the built-in `replace()` function and should have a ...
Here is the Python code to solve the given problem in the markdown block: ```python def replace_pattern(pattern: str, text: str) -> str: """ Replaces all occurrences of a given pattern with the word "lessons" in the given text. The replacement is case-insensitive and preserves the original case of the lette...
python_sharegpt_23k
2,681
Write a Python function to calculate the sum of all the digits in a given string, excluding any punctuation marks or special characters. The function should handle strings with mixed characters, including letters, digits, and punctuation. The code should start with: ```python def sum_of_digits(s: str) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_digits(s: str) -> int: """ Calculate the sum of all digits in a given string, excluding any punctuation marks or special characters. Args: s (str): The input string containing mixed characters. Retur...
python_sharegpt_23k
2,682
Write a Python function to determine if two given strings are permutations of each other. The function should be case-sensitive, consider spaces and punctuation marks, and should have a time complexity of O(n log n) and a space complexity of O(1). The function should not use any built-in sorting functions or libraries....
Here is the Python code to solve the given problem in the markdown block: ```python def are_permutations(str1: str, str2: str) -> bool: """ Determine if two given strings are permutations of each other. Args: str1 (str): The first string to compare. str2 (str): The second string to compare....
python_sharegpt_23k
2,685
Write a Python function to print each string in a list of 1000 strings in reverse order, each on a separate line, using a single loop. The function should not modify the original list or create a new list, and it should adhere to the constraints of time complexity O(n) and space complexity O(1). The code should start ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_strings_in_reverse(strings: List[str]) -> None: """ Prints each string in the given list in reverse order, each on a separate line. Args: strings (List[str]): A list of strings to ...
python_sharegpt_23k
2,689
Write a Python function to parse a given sentence string and return a list of words. The parsing should be case-insensitive and should remove any punctuation marks from the string before splitting it into words. Additionally, the function should handle multiple spaces between words and return an empty list if the strin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def parse_sentence(sentence: str) -> List[str]: """ Parses a given sentence string and returns a list of words. The parsing is case-insensitive and removes any punctuation marks. Args: ...
python_sharegpt_23k
2,690
Write a Python function to compare two strings using a given regular expression and return the number of matching characters. Additionally, if there are any characters that are present in `string1` but not in `string2` or vice versa, consider them as non-matching characters. The regular expression to be used is `^[a-zA...
Here is the Python code to solve the given problem in the markdown block: ```python import re def compare_strings(string1: str, string2: str) -> int: """ Compare two strings using the given regular expression and return the number of matching characters. Additionally, if there are any characters that are p...
python_sharegpt_23k
2,692
Write a Python function to calculate the sum of the squares of two given integers. The function should also check if the resulting sum is a perfect square. If it is, return the sum of the squares; otherwise, return -1. Additionally, the function should handle negative input numbers. If any of the parameters is negative...
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_squares(num1: int, num2: int) -> int: """ Calculate the sum of the squares of two integers and check if the result is a perfect square. If the result is a perfect square, return the sum of the squares; otherwise, ...
python_sharegpt_23k
2,695
Implement a stable sorting algorithm in Python without using any built-in sorting functions or methods. The algorithm should be able to handle both ascending and descending sorting orders based on a given flag. The code should start with: ```python from typing import List def custom_sort(arr: List[int], ascending: boo...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def custom_sort(arr: List[int], ascending: bool = True) -> List[int]: """ Sorts the input list using a stable Merge Sort algorithm. Args: arr (List[int]): The list of integers to be sorted. ...
python_sharegpt_23k
2,702
Write a Python function to generate a new list of integers containing only the prime numbers from a given list of integers. The function should not use any built-in functions or libraries to check if a number is prime. Instead, you should implement a function that uses bitwise operations to determine if a number is pri...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_prime_numbers(numbers: List[int]) -> List[int]: """ Generate a new list of integers containing only the prime numbers from the given list. Args: numbers (List[int]): The list of int...
python_sharegpt_23k
2,703
Write a Python function to filter and sort a list of user details based on specific criteria. The function should return a dictionary where the keys are the names of the filtered users and the values are their occupations. The filtering criteria are: 1. The user's age must be more than 25. 2. The user's occupation must...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def filter_and_sort_users(user_details: List[Dict[str, any]]) -> Dict[str, str]: """ Filters and sorts a list of user details based on specific criteria. Args: user_details (List[Dict[...
python_sharegpt_23k
2,708
Write a Python function to implement a modified version of the Bubble Sort algorithm that sorts an array of integers in ascending order. The function should have a time complexity of O(n^2) and should efficiently handle arrays of up to 10000 elements. Do not use any built-in sorting methods or libraries. The function s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers in ascending order using a modified Bubble Sort algorithm. Args: arr (List[int]): The array of integers to be sor...
python_sharegpt_23k
2,714
Write a Python function to multiply two positive integers without using the multiplication operator. The function should achieve this by leveraging bitwise operations and should have a time complexity less than O(n^2), where n is the number of bits in the binary representation of the larger number. Additionally, the fu...
Here is the Python code to solve the given problem in the markdown block: ```python def multiply_without_operator(a: int, b: int) -> int: """ Multiplies two positive integers without using the multiplication operator. Args: a (int): The first positive integer. b (int): The second positive i...
python_sharegpt_23k
2,719
Write a Python function to divide two positive integers without using the division operator and with a time complexity of O(log N), where N is the number of digits in the dividend. The function should handle the case where the divisor is zero and return -1 as the result. The dividend and divisor will be positive intege...
Here is the Python code to solve the given problem in the markdown block: ```python def divide_positive_integers(dividend: int, divisor: int) -> int: """ Divide two positive integers without using the division operator and with a time complexity of O(log N), where N is the number of digits in the dividend. ...
python_sharegpt_23k
2,729
Write a Python function to calculate the sum of positive numbers in a given list. The function should handle the following cases: 1. If the input list is empty, raise a `ValueError` with the message "The input list is empty." 2. If the input list contains any non-numeric values, raise a `ValueError` with the message "T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_positive_numbers(numbers: List[int]) -> int: """ Calculate the sum of positive numbers in a given list. Args: numbers (List[int]): The list of numbers to process. Returns: ...
python_sharegpt_23k
2,731
Write a Python function to find the index of the first occurrence of a given item in a sorted array that may contain duplicate non-negative integer and float values. The function should use a recursive binary search algorithm with a time complexity of O(log n) and be able to handle arrays with up to 10^6 elements. If t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def find_first_occurrence(arr: List[Union[int, float]], item: Union[int, float]) -> int: """ Find the index of the first occurrence of a given item in a sorted array. Args: arr (List[...
python_sharegpt_23k
2,736
Write a Python function to generate XML tags for a given list of strings. Each XML tag should include an attribute called "id" with a unique value for each tag. The unique values should be generated using a specific pattern: "tag_<index>", where `<index>` starts at a random number between 1 and 10 and increments by a r...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_xml_tags(strings: List[str]) -> List[str]: """ Generate XML tags for the given list of strings. Each XML tag includes an attribute "id" with a unique value generated using ...
python_sharegpt_23k
2,740
Write a Python function to determine if a given number `n` is a prime palindrome. A prime palindrome is a number that is both a prime number and a palindrome. The function should return `True` if the number is a prime palindrome, and `False` otherwise. The code should start with: ```python def is_prime_palindrome(n: i...
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime_palindrome(n: int) -> bool: """ Determine if a given number `n` is a prime palindrome. Args: n (int): The number to check. Returns: bool: True if `n` is a prime palindrome, False otherwise....
python_sharegpt_23k
2,746
Write a Python function to determine if a given number is prime using a probabilistic primality test algorithm, such as the Miller-Rabin test. Additionally, create a function to find the nth prime number with a time complexity of O(n^2). Both functions should handle invalid inputs, such as negative numbers or non-integ...
Here is the Python code to solve the given problem in the markdown block: ```python import random def is_prime(number: int) -> bool: """ Determine if a given number is prime using the Miller-Rabin probabilistic primality test. Args: number (int): The number to check for primality. Returns: ...
python_sharegpt_23k
2,751
Write a Python function to find the k-th smallest element in a given list of unique integers. The list will always have an odd number of elements. The function should be efficient and avoid sorting the entire list if possible. The code should start with: ```python from typing import List def kth_smallest(arr: List[in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def kth_smallest(arr: List[int], k: int) -> int: """ Finds the k-th smallest element in a list of unique integers. Args: arr (List[int]): A list of unique integers with an odd number of elem...
python_sharegpt_23k
2,753
Write a Python function to find and return a list of all prime numbers between 0 and a given upper limit `n` in descending order. The function should use a single loop and should not make use of any built-in functions or libraries to check for prime numbers. The code should start with: ```python from typing import List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_primes_descending(n: int) -> List[int]: """ Find all prime numbers between 0 and n in descending order. Args: n (int): The upper limit to find prime numbers. Returns: L...
python_sharegpt_23k
2,763
Write a Python function named `customSort` that implements a sorting algorithm for an array that only needs 1 iteration and has a time complexity of O(n^2). The function should sort the input array in ascending order without using any built-in sorting functions or libraries. The input array can contain positive and neg...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def customSort(arr: List[int]) -> List[int]: """ Sorts the input array in ascending order using a single iteration with a time complexity of O(n^2). Args: arr (List[int]): The input array to...
python_sharegpt_23k
2,768
Write a Python function to count the number of occurrences of each unique English alphabet letter in a given string, ignoring any punctuation marks, special characters, and spaces. The function should handle uppercase and lowercase letters as separate entities and return a dictionary where the keys are the letters and ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def count_unique_alphabets(input_string: str) -> Dict[str, int]: """ Counts the number of occurrences of each unique English alphabet letter in the given string, ignoring any punctuation marks, speci...
python_sharegpt_23k
2,775
Write a Python function to delete all prime numbers from the first `n` elements of a given array of integers. The function should return the modified array. The function should not use any built-in functions or libraries to check for prime numbers and should handle edge cases such as when `n` is less than or equal to 0...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def delete_primes_from_array(arr: List[int], n: int) -> List[int]: """ Deletes all prime numbers from the first n elements of the given array. Args: arr (List[int]): The array of integers fr...
python_sharegpt_23k
2,776
Write a Python function to calculate the nth Fibonacci number using an iterative approach to ensure O(1) space complexity. The function should not use any built-in mathematical functions or libraries. The code should start with: ```python def fibonacci_iterative(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python def fibonacci_iterative(n: int) -> int: """ Calculate the nth Fibonacci number using an iterative approach with O(1) space complexity. Args: n (int): The position in the Fibonacci sequence to calculate. Retur...
python_sharegpt_23k
2,784
Write a Python function to determine if two given strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. The function should handle cases where the input strings contain spaces, punctuation marks, and should be case-insensitive. The function shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import string from collections import Counter def check_anagrams(pairs: List[Tuple[str, str]]) -> List[bool]: """ Determine if each pair of strings in the input list are anagrams of each other. ...
python_sharegpt_23k
2,785
Write a Python function to create a list of a specified length with random integers between -1000 and 1000, ensuring that the list does not contain any duplicate values and contains no more than 7 negative numbers. The function should handle cases where the generated list contains more than 7 negative numbers by discar...
Here is the Python code to solve the given problem in the markdown block: ```python import random from typing import List def create_list_with_constraints(length: int) -> List[int]: """ Creates a list of the specified length with random integers between -1000 and 1000, ensuring no duplicate values and no m...
python_sharegpt_23k
2,787
Write a Python function to reverse a given string without using any built-in functions or methods that directly reverse a string. The function should handle special characters and whitespace, and should preserve the original case of each character in the reversed string. The code should start with: ```python def rever...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(input_str: str) -> str: """ Reverses the input string without using any built-in functions or methods that directly reverse a string. Preserves the original case of each character and handles special chara...
python_sharegpt_23k
2,798
Write a Python function to parse a URL query string and return a dictionary of key-value pairs. If a key is repeated in the query string, only the last occurrence should be stored in the dictionary. The URL may contain special characters such as percent-encoded values. The function should start with: ```python from typ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict from urllib.parse import unquote def parse_query_string(url: str) -> Dict[str, str]: """ Parses a URL query string and returns a dictionary of key-value pairs. If a key is repeated in the query strin...
python_sharegpt_23k
2,800
Write a Python function to remove all occurrences of a given number `num` from an input array `array`. The function should achieve this without using the `remove()` method and should have a time complexity of O(n), where n is the length of the array. The function should start with: ```python from typing import List de...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_all_occurrences(array: List[int], num: int) -> List[int]: """ Removes all occurrences of the given number `num` from the input array `array`. Args: array (List[int]): The input ar...
python_sharegpt_23k
2,802
Write a Python function to calculate the Levenshtein distance between two strings. The Levenshtein distance is defined as the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other. The function should take two strings as input and return an integ...
Here is the Python code to solve the given problem in the markdown block: ```python def levenshtein_distance(str1: str, str2: str) -> int: """ Calculate the Levenshtein distance between two strings. The Levenshtein distance is the minimum number of single-character edits (insertions, deletions, or subs...
python_sharegpt_23k
2,810
Implement a Merge Sort algorithm to sort an unsorted array of numbers in ascending order without using any comparison-based sorting algorithm. The implementation should be recursive and should not use any extra space for merging the arrays. The time complexity of the solution should be O(n log n), and it should handle ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts an unsorted array of numbers in ascending order using a Merge Sort algorithm. The implementation does not use any comparison-based sorting and d...
python_sharegpt_23k
2,818
Write a Python function to calculate the number of distinct values that can be inserted into a balanced binary tree containing `N` nodes, ensuring that the tree remains balanced at all times. The function should have a time complexity better than O(N^2). The code should start with: ```python import math def count_dis...
Here is the Python code to solve the given problem in the markdown block: ```python import math def count_distinct_values(N: int) -> int: """ Calculate the number of distinct values that can be inserted into a balanced binary tree containing N nodes. Args: N (int): The number of nodes in the balan...
python_sharegpt_23k
2,823
Write a Python function to find the most frequent element in a list that appears at least three times. The input list will contain at most \(10^6\) elements, and each element will be an integer between \(-10^9\) and \(10^9\). You are not allowed to use any built-in sorting or counting functions in your solution. The c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def most_frequent_element(lst: List[int]) -> Optional[int]: """ Find the most frequent element in a list that appears at least three times. Args: lst (List[int]): The input list of...
python_sharegpt_23k
2,824
Write a Python function to find and return a list of all prime numbers between 1000 and 1100, excluding any numbers that are divisible by both 5 and 7. The function should start with: ```python from typing import List def find_primes_in_range(start: int, end: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_primes_in_range(start: int, end: int) -> List[int]: """ Find all prime numbers within the specified range [start, end], excluding numbers divisible by both 5 and 7. Args: start (int...
python_sharegpt_23k
2,826
Write a Python function to count the occurrences of each unique alphabetical character in a given string, ignoring case and whitespace. The function should return a dictionary where the keys are the characters and the values are their respective counts. Special characters and numbers should be ignored. The code should...
Here is the Python code to solve the given problem in the markdown block: ```python def count_unique_characters(string: str) -> dict: """ Counts the occurrences of each unique alphabetical character in a given string, ignoring case and whitespace. Args: string (str): The input string to count uniqu...
python_sharegpt_23k
2,828
Write a Python function to convert a given list of dictionaries to a tuple of tuples, where each inner tuple contains the capitalized name and age of a person. Each person's age must be a positive integer. If a person's name or age is missing or invalid, skip that dictionary. The resulting tuple of tuples must be sorte...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def sort_persons_list(persons: List[Dict[str, any]]) -> Tuple[Tuple[str, int], ...]: """ Convert a list of dictionaries to a tuple of tuples, where each inner tuple contains the capitalized ...
python_sharegpt_23k
2,830
Write a Python function to sort a list of integers in ascending order using the bubble sort algorithm. You are not allowed to use any built-in sorting functions or libraries. The time complexity of your algorithm must be O(n^2), and you are not allowed to use any additional data structures or variables besides the give...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def bubble_sort(nums: List[int]) -> List[int]: """ Sorts a list of integers in ascending order using the bubble sort algorithm. Args: nums (List[int]): The list of integers to be sorted. ...
python_sharegpt_23k
2,835
Write a Python function `same_frequency_recursive(num1, num2)` that takes in two integers `num1` and `num2` and determines if they have the same frequency of digits. The function should use recursion to count the frequency of digits in each number and should not convert the numbers to strings or use any built-in functi...
Here is the Python code to solve the given problem in the markdown block: ```python def same_frequency_recursive(num1: int, num2: int) -> bool: """ Determines if two integers have the same frequency of digits using recursion. Args: num1 (int): The first integer. num2 (int): The second integ...
python_sharegpt_23k
2,837
Write a Python function to calculate the sum of the first `n` prime numbers. The function should take an integer `n` as input and return the sum of the first `n` prime numbers. The code should start with: ```python def sum_of_first_n_primes(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_first_n_primes(n: int) -> int: """ Calculate the sum of the first n prime numbers. Args: n (int): The number of prime numbers to sum. Returns: int: The sum of the first n prime numbers. "...
python_sharegpt_23k
2,838
Write a Python function to create a dictionary from a list of tuples, where each tuple consists of a color name and its value. The function should ensure that the dictionary is created with a time complexity of O(n), where n is the length of the input list. Additionally, the function should check for duplicate color na...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Dict def create_color_dictionary(color_list: List[Tuple[str, str]]) -> Dict[str, str]: """ Creates a dictionary from a list of tuples, where each tuple consists of a color name and its value. ...
python_sharegpt_23k
2,841
Write a Python function to determine if the elements of a given array are in strictly increasing order without using any built-in sorting functions or methods. The array may contain both positive and negative integers. The function should return `True` if the elements are in strictly increasing order and `False` otherw...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_strictly_increasing(arr: List[int]) -> bool: """ Determine if the elements of the given array are in strictly increasing order without duplicates. Args: arr (List[int]): The array of ...
python_sharegpt_23k
2,845
Write a Python function to reverse an array of size `n` in place, where `n` is a positive integer not exceeding 10^9. The array elements are integers between 1 and 10^9 (inclusive). Implement an efficient algorithm with a time complexity of O(n) and a space complexity of O(1). Ensure that the algorithm does not use any...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def reverse_array(arr: List[int]) -> List[int]: """ Reverses an array of integers in place. Args: arr (List[int]): The array of integers to be reversed. Returns: List[int]: The ...
python_sharegpt_23k
2,848
Write a Python function to reverse a given string without using any built-in string manipulation functions or libraries. The solution should have a time complexity of O(n), where n is the length of the string. Additionally, you are not allowed to use any additional data structures such as lists, arrays, or stacks. You ...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string(s: str) -> str: """ Reverses the given string without using any built-in string manipulation functions or libraries. Args: s (str): The input string to be reversed. Returns: str: The ...
python_sharegpt_23k
2,851
Write a Python function to find the first index of a given character in a string without using any built-in string or array methods such as `indexOf`, `find`, or `includes`. The function should have a time complexity of O(n) and a space complexity of O(1), where n is the length of the string. The string will not contai...
Here is the Python code to solve the given problem in the markdown block: ```python def find_character(string: str, character: str) -> int: """ Find the first index of a given character in a string without using built-in string or array methods. Args: string (str): The string to search within. ...
python_sharegpt_23k
2,852
Write a Python function to compute the volume of a rectangular room in cubic feet, ensuring that the function handles potential errors and invalid inputs. The function should check if the calculated volume exceeds a maximum allowed value of 1000 cubic feet and raise an error with a custom message if it does. Additional...
Here is the Python code to solve the given problem in the markdown block: ```python def compute_volume(length: int, width: int, height: int) -> int: """ Compute the volume of a rectangular room in cubic feet, ensuring valid inputs and volume limits. Args: length (int): The length of the room in fee...
python_sharegpt_23k
2,865
Write a Python function to calculate the perimeter and area of a triangle given the lengths of its three sides. The function should include validation to ensure that the provided side lengths form a valid triangle according to the triangle inequality theorem. If the side lengths do not form a valid triangle, the functi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Tuple import math # Create a cache dictionary to store previously calculated perimeters and areas cache = {} def calculate_triangle_properties(side1: float, side2: float, side3: float) -> Tuple[float, float]: ""...
python_sharegpt_23k
2,867
Write a Python function to sort a list of integers in descending order using the Quick Sort algorithm. The function should be implemented in-place, meaning it should modify the input list directly without creating a new list. The function should handle lists with duplicate elements and should be designed to sort the li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def quick_sort_descending(lst: List[int]) -> List[int]: """ Sorts the input list of integers in descending order using the Quick Sort algorithm. Args: lst (List[int]): The list of integers t...
python_sharegpt_23k
2,870
Write a Python function to calculate the nth term of the Fibonacci sequence using a recursive approach. The function should handle at least three base cases and at least three recursive calls within its implementation. The time complexity of the recursive function should be O(2^n), where n is the position in the Fibona...
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci(n: int) -> int: """ Calculate the nth term of the Fibonacci sequence using a recursive approach. The Fibonacci sequence is defined as: - F(0) = 0 - F(1) = 1 - F(n) = F(n-1) + F(n-2) for n > 1 ...
python_sharegpt_23k
2,877
Write a Python function to generate an array of the first `n` prime numbers where each prime number is a palindrome and contains at least 5 digits. The function should return the array of these prime numbers. The code should start with: ```python from typing import List def generate_prime_palindromes(n: int) -> List[...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(num: int) -> bool: """ Check if a number is prime. Args: num (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if...
python_sharegpt_23k
2,878
Write a Python function to determine if a given triangle is a right-angled triangle. The function should take three parameters representing the lengths of the three sides of the triangle and return `True` if the triangle is a right-angled triangle, and `False` otherwise. The function should adhere to the following cons...
Here is the Python code to solve the given problem in the markdown block: ```python def is_right_angled_triangle(a: int, b: int, c: int) -> bool: """ Determine if a given triangle with sides a, b, and c is a right-angled triangle. Args: a (int): Length of the first side. b (int): Length of ...
python_sharegpt_23k
2,879
Write a Python function to compute the square root of a positive integer without using the built-in square root function or any math library functions such as `pow` or `log`. The solution should have a time complexity of O(log n), where n is the given number. The solution should also be accurate up to 10 decimal places...
Here is the Python code to solve the given problem in the markdown block: ```python def compute_square_root(n: int) -> float: """ Compute the square root of a positive integer without using the built-in square root function or any math library functions. The solution has a time complexity of O(log n) and is...
python_sharegpt_23k
2,885
Write a Python function to generate a list of prime numbers from 1 to n, excluding multiples of 3, with a time complexity of O(n) and a space complexity of O(1). The function should use the Sieve of Eratosthenes algorithm to efficiently mark non-prime numbers and exclude multiples of 3 during the process. The code sho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_primes_excluding_multiples_of_3(n: int) -> List[int]: """ Generate a list of prime numbers from 1 to n, excluding multiples of 3. Args: n (int): The upper limit to generate prim...
python_sharegpt_23k
2,892
Implement a quick sort algorithm that can handle a large input size of `n` (where `n > 10^6`) efficiently. The algorithm should have a time complexity of O(n log n) and should not exceed the space complexity of O(log n). The input list may contain duplicate numbers and the algorithm should be able to handle them approp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def quicksort(arr: List[int]) -> List[int]: """ Sorts a list of integers using the quick sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Returns: List[...
python_sharegpt_23k
2,896
Write a Python function to determine the number of rows and columns in a given matrix. The matrix is guaranteed to have at least one row and one column, and it can contain integers, floats, and strings. If the matrix has rows of varying lengths, the function should return the number of rows and a list of the lengths of...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def find_matrix_dimensions(matrix: List[List[Union[int, float, str]]]) -> Union[int, List[int]]: """ Determine the number of rows and columns in a given matrix. Args: matrix (List[Lis...