source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
python_sharegpt_23k
11,560
Write a Python function to compare two lists of dictionaries and determine if they are equivalent based on the 'id' and 'name' attributes. The function should return `True` if the objects in both lists have the same 'id' and 'name' attributes, considering the order of the objects. Additionally, if an object in `list1` ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def are_lists_equivalent(list1: List[Dict[str, any]], list2: List[Dict[str, any]]) -> bool: """ Compare two lists of dictionaries and determine if they are equivalent based on the 'id' and 'name' a...
python_sharegpt_23k
11,562
Write a Python function to filter out prime numbers from a given list, remove duplicates, and sort the resulting list in descending order without using any built-in sorting or duplicate removal functions. The original list can contain up to 1 million elements. The function should start with: ```python from typing impor...
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. Returns: bool: True if the number is prime, False otherwise. """ if n <...
python_sharegpt_23k
11,565
Write a Python function to process a list of strings, removing all special characters and capitalizing the first letter of each word within each string. The function should handle strings that contain special characters and should ignore these characters while capitalizing the words. 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 import re def capitalize_words_ignore_special(strings: List[str]) -> List[str]: """ Processes a list of strings to remove special characters and capitalize the first letter of each word. Args: ...
python_sharegpt_23k
11,576
Write a Python function to validate and transform a list of records. Each record consists of a name and a location separated by a tab character. The function should perform the following tasks: 1. Validate the data integrity by checking that each name and location is not empty. 2. If any name or location is empty, disp...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def process_records(data: List[str]) -> None: """ Validates and transforms a list of records. Each record consists of a name and a location separated by a tab character. Args: data (List[str...
python_sharegpt_23k
11,578
Write a Python function to check if two variables have the same type and, if applicable, additional properties such as length for lists and keys for dictionaries. The function should return `True` if the variables meet all the criteria, otherwise `False`. The code should start with: ```python def check_variables(var1,...
Here is the Python code to solve the given problem in the markdown block: ```python def check_variables(var1, var2) -> bool: """ Check if two variables have the same type and, if applicable, additional properties such as length for lists and keys for dictionaries. Args: var1: The first variable to ...
python_sharegpt_23k
11,579
Write a Python function to find all unique prime factors of a given positive integer in ascending order. The function should handle numbers up to 1,000,000 efficiently and should be able to handle inputs within a reasonable time limit for numbers up to 10^9. 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 get_prime_factors(num: int) -> List[int]: """ Returns a list of all unique prime factors of a given positive integer in ascending order. Args: num (int): The positive integer for which t...
python_sharegpt_23k
11,581
Write a Python function to reverse a given string in-place with a time complexity of O(n) and a space complexity of O(1), where n is the length of the string. The function should handle strings containing Unicode characters properly. The code should start with: ```python def reverse_string_in_place(s: str) -> str: ```...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string_in_place(s: str) -> str: """ Reverses the given string in-place with a time complexity of O(n) and a space complexity of O(1). Args: s (str): The input string to be reversed. Returns: ...
python_sharegpt_23k
11,582
Write a Python function to extract all uppercase letters from a given string and convert them to lowercase. The function should return a list of these lowercase letters. Ignore all other characters in the string. The code should start with: ```python from typing import List def extract_uppercase_to_lowercase(input_st...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def extract_uppercase_to_lowercase(input_string: str) -> List[str]: """ Extracts all uppercase letters from the input string and converts them to lowercase. Args: input_string (str): The inp...
python_sharegpt_23k
11,583
Write a Python function to count the occurrences of each unique element in a given array of integers. The function should return a dictionary where the keys are the unique elements from the array and the values are their respective counts. The function should remove any duplicate elements from the array before counting...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def count_unique_elements(arr: List[int]) -> Dict[int, int]: """ Counts the occurrences of each unique element in the given array of integers. Args: arr (List[int]): The array of integ...
python_sharegpt_23k
11,591
Write a Python function to generate a random number within a specified range. The function should accept two parameters: `start` and `end`, which define the inclusive range for the random number. The function should return the generated random number. The code should start with: ```python import random def generate_r...
Here is the Python code to solve the given problem in the markdown block: ```python import random def generate_random_number(start: int, end: int) -> int: """ Generates a random integer within the specified inclusive range [start, end]. Args: start (int): The lower bound of the range (inclusive). ...
python_sharegpt_23k
11,592
Write a Python function to merge two dictionaries into another dictionary, ensuring that the merged dictionary only contains key-value pairs where the key is a string and the value is a positive integer. If a key-value pair in either `dict1` or `dict2` does not meet this requirement, it should be skipped. The code sho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def merge_dictionaries(dict1: Dict[str, int], dict2: Dict[str, int]) -> Dict[str, int]: """ Merge two dictionaries into another dictionary, ensuring that the merged dictionary only contains key-value pai...
python_sharegpt_23k
11,603
Write a Python function to process a list of integers and return a dictionary where the keys are the unique integers from the list, and the values are lists of indices where these integers appear in the original list. The function should handle the case where the input list is empty by returning an empty dictionary. T...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def index_map(numbers: List[int]) -> Dict[int, List[int]]: """ Create a dictionary where the keys are the unique integers from the input list, and the values are lists of indices where these in...
python_sharegpt_23k
11,606
Write a Python function to calculate the sum of corresponding elements from two given arrays of integers. The resulting sum should be returned as an array. If the lengths of the two arrays are not equal, the sum should only be calculated up to the length of the shorter array. The code should start with: ```python from...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_corresponding_elements(a: List[int], b: List[int]) -> List[int]: """ Calculate the sum of corresponding elements from two given arrays of integers. If the lengths of the two arrays are not eq...
python_sharegpt_23k
11,607
Write a Python function to generate the first n prime numbers and return them as a list. The function should efficiently determine if a number is prime and continue generating primes until the desired count is reached. The code should start with: ```python from typing import List def generate_first_n_primes(n: int) -...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_first_n_primes(n: int) -> List[int]: """ Generate the first n prime numbers and return them as a list. Args: n (int): The number of prime numbers to generate. Returns: ...
python_sharegpt_23k
11,608
Write a Python function to calculate the sum of all elements in a given list without using any built-in functions or operators for summation. Instead, implement your own algorithm to iterate through the list and calculate the sum manually. Additionally, you are not allowed to use any temporary variables or data structu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def manual_sum(lst: List[int]) -> int: """ Calculate the sum of all elements in the given list without using any built-in functions or operators for summation. Args: lst (List[int]): The lis...
python_sharegpt_23k
11,609
Write a Python function to perform a binary search on a sorted list of integers to find the index of a target element. If the target element is found, the function should return its index; otherwise, it should return -1. The function should have a time complexity of O(log n), where n is the length of the list. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search(arr: List[int], target: int) -> int: """ Perform a binary search on a sorted list to find the index of a target element. Args: arr (List[int]): A sorted list of integers. ...
python_sharegpt_23k
11,618
Write a Python function to find all common items between two lists, ignoring any duplicate common items in the resulting list. The input lists may contain integers, floating-point numbers, strings, and nested lists. If a nested list is encountered, the function should flatten the nested list and consider its elements a...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def find_common_items(list1: List[Union[int, float, str, List]], list2: List[Union[int, float, str, List]]) -> List[Union[int, float, str]]: """ Find all common items between two lists, ignoring a...
python_sharegpt_23k
11,621
Write a Python function to sort a dictionary by the sum of its keys and values. The dictionary will contain string keys and integer values. The sorting should be done in ascending order based on the sum of the ASCII values of the characters in the key and the value. The function should use only one loop to achieve this...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def sort_dict_by_sum(d: Dict[str, int]) -> Dict[str, int]: """ Sorts a dictionary by the sum of the ASCII values of the characters in the key and the value. Args: d (Dict[str, int]): The dic...
python_sharegpt_23k
11,622
Write a Python function to calculate the nth Fibonacci number using a recursive approach with memoization. The function should handle cases where a negative number or a non-integer is provided as input by raising appropriate exceptions. The code should start with: ```python def fibonacci(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def fibonacci(n: int) -> int: """ Calculate the nth Fibonacci number using a recursive approach with memoization. Args: n (int): The position in the Fibonacci sequence to calculate. Returns: int: The nt...
python_sharegpt_23k
11,629
Write a Python function to find the most frequent element in a given array with a time complexity of O(n). The function should not use any built-in functions or data structures other than basic ones like lists and dictionaries. Additionally, the function must handle arrays with up to 1 million elements. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python def find_most_frequent_element(arr): """ Find the most frequent element in a given array with a time complexity of O(n). Args: arr (list): The array from which to find the most frequent element. Returns: ...
python_sharegpt_23k
11,630
Write a Python function to extract and return all values from a given dictionary that are greater than 5 and less than 9, sorted in ascending order. The function should handle any dictionary with integer values. The code should start with: ```python from typing import Dict, List def extract_and_sort_values(my_dict: D...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, List def extract_and_sort_values(my_dict: Dict[str, int]) -> List[int]: """ Extracts and returns all values from the given dictionary that are greater than 5 and less than 9, sorted in ascending order. ...
python_sharegpt_23k
11,637
Write a Python function to compute the occurrence of each unique alphanumeric character in a given string, excluding any whitespace characters, and return the characters in descending order of their occurrence count. The solution should have a time complexity of O(n log n). The code should start with: ```python from t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List from collections import defaultdict def count_alphanumeric_chars(string: str) -> List[str]: """ Compute the occurrence of each unique alphanumeric character in a given string, excluding any whitespac...
python_sharegpt_23k
11,641
Write a Python function to find the intersection of two given arrays of integers. The intersection is defined as the set of elements that are common to both arrays, with no duplicates. The order of elements in the output array does not matter. The function should not use any built-in array methods or functions such as ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_intersection(array1: List[int], array2: List[int]) -> List[int]: """ Find the intersection of two arrays of integers. Args: array1 (List[int]): The first array of integers. ...
python_sharegpt_23k
11,642
Write a Python function to check if a given element is present in a list or a substring is present in a given string. The function should return a tuple where the first element is a boolean indicating the presence of the element in the list, and the second element is a boolean indicating the presence of the substring i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Union, List, Tuple def check_presence(element: Union[int, str], container: Union[List[int], List[str], str]) -> Tuple[bool, bool]: """ Check if the given element is present in a list or a substring is present...
python_sharegpt_23k
11,643
Write a Python function to merge two sorted lists into a single sorted list using tuples. The function should take two lists of integers as input and return a single sorted list. The function should use tuples to temporarily store and compare elements from the two lists. The code should start with: ```python from typin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]: """ Merges two sorted lists into a single sorted list using tuples for temporary storage and comparison. Args: list1 ...
python_sharegpt_23k
11,646
Write a Python function to calculate the mode of a given list of numbers. The mode is the number(s) that appear(s) most frequently in the list. If multiple numbers have the same highest frequency, return all of them. The list may contain duplicate numbers and negative numbers. You are not allowed to use any built-in fu...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def calculate_mode(numbers: List[int]) -> List[int]: """ Calculate the mode(s) of a given list of numbers. The mode is the number(s) that appear(s) most frequently in the list. If multiple numbers ha...
python_sharegpt_23k
11,648
Write a Python function to calculate the length of a linked list without using any additional memory. The function should have a time complexity of O(n) and a space complexity of O(1), where n is the length of the linked list. The function should take the head node of the linked list as input and return the length of t...
Here is the Python code to solve the given problem in the markdown block: ```python class Node: def __init__(self, val, next=None): self.val = val self.next = next def get_linked_list_length(head: Node) -> int: """ Calculate the length of a linked list. Args: head (Node): The h...
python_sharegpt_23k
11,649
Write a Python function to count the number of items in a given list that are not 'orange' and are also present in another list of fruits. The function should be optimized for readability and efficiency. The code should start with: ```python from typing import List def count_non_orange_fruits(fruits: List[str], items:...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_non_orange_fruits(fruits: List[str], items: List[str]) -> int: """ Counts the number of items in the 'items' list that are not 'orange' and are also present in the 'fruits' list. Args: ...
python_sharegpt_23k
11,656
Write a Python function to find the maximum score from a given set of scores without using any loops or conditional statements. The function should take a set of integers as input and return the maximum value in the set. The code should start with: ```python from typing import Set def find_maximum_score(scores: Set[i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Set def find_maximum_score(scores: Set[int]) -> int: """ Find the maximum score from a given set of scores. Args: scores (Set[int]): A set of integers representing the scores. Returns: ...
python_sharegpt_23k
11,657
Write a Python function to generate a list of prime numbers within a given range [start, end]. The function should efficiently determine if a number is prime and return a list of all prime numbers in the specified range. The code should start with: ```python from typing import List def generate_primes_in_range(start:...
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. Returns: bool: True if the number is prime, False otherwise. """ if n <...
python_sharegpt_23k
11,658
Write a Python function to sum corresponding elements of two iterables. If the lengths of the two iterables are not equal, the function should raise a `ValueError` with the custom error message "Both iterables must have the same length". The function should be generic and work with any two iterables (e.g., lists, tuple...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Iterable, List def sum_corresponding_elements(iterable1: Iterable, iterable2: Iterable) -> List: """ Sums corresponding elements of two iterables and returns the result as a list. Args: iterable1...
python_sharegpt_23k
11,659
Write a Python function to sort an integer list using a custom merge sort algorithm. The function should handle duplicate elements in the input list and maintain their relative order in the sorted output. The time complexity of the sorting algorithm should be O(n log n), and the space complexity should be O(1). The fun...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_integer_list(arr: List[int]) -> List[int]: """ Sorts an integer list using a custom merge sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Returns: ...
python_sharegpt_23k
11,666
Write a Python function to calculate the sum of the digits of a given positive integer without using any built-in functions for converting the integer to a string or manipulating strings. The solution should have a time complexity of O(log n), where n is the given number. You are not allowed to use any external librari...
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_digits(n: int) -> int: """ Calculate the sum of the digits of a given positive integer. Args: n (int): The positive integer whose digits are to be summed. Returns: int: The sum of the digits ...
python_sharegpt_23k
11,670
Write a Python function to unpack a given list of tuples and calculate the average age of the people in the tuples. Each tuple should contain exactly 10 elements, and the names should be unique. Each person's age should be between 18 and 60. The function should validate the input tuples to ensure they meet the followin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def calculate_average_age(tuples: List[Tuple]) -> int: """ Calculate the average age of people from a list of tuples. Each tuple should contain exactly 10 elements: 1. Name (string) 2...
python_sharegpt_23k
11,672
Write a Python function to generate all prime numbers less than a given number `n` efficiently, ensuring that the function can handle inputs up to `10^9`. The function should return the prime numbers in descending order. The code should start with: ```python from typing import List def generate_primes_descending(n: in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def generate_primes_descending(n: int) -> List[int]: """ Generate all prime numbers less than a given number `n` and return them in descending order. Args: n (int): The upper lim...
python_sharegpt_23k
11,673
Write a Python function to remove all prime numbers from a given list of integers. A prime number is a number greater than 1 that has no divisors other than 1 and itself. The function should return a new list containing only the non-prime numbers from the input list. The code should start with: ```python from typing i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def is_prime(num: int) -> bool: """ Helper function to check if a number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the num...
python_sharegpt_23k
11,675
Write a Python function to find and return all prime numbers within a given range `[start, end]`. The function should be efficient and correctly identify prime numbers. The code 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 import math def find_primes_in_range(start: int, end: int) -> List[int]: """ Find and return all prime numbers within the given range [start, end]. Args: start (int): The starting number of ...
python_sharegpt_23k
11,678
Write a Python function to filter out the prime numbers from a given list of integers. The function should return a new list containing only the prime numbers. The function should be able to handle negative integers as well, treating them the same as their positive counterparts when determining their primality. For exa...
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
11,690
Write a Python function to find the prime factors of a given positive integer `n` without using any built-in prime factorization functions or libraries. The function should have a time complexity of O(sqrt(n)) and a space complexity of O(1), meaning it should not use any additional data structures to store the prime fa...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def prime_factors(n: int) -> List[int]: """ Returns a list of prime factors of a given positive integer `n`. The function uses an efficient algorithm with a time complexity of O(sqrt(n)) and a s...
python_sharegpt_23k
11,692
Write a Python function to sort a given list of numbers from smallest to largest without using any built-in sorting functions or libraries. The sorting algorithm must have a time complexity of O(n^2). The function should start with: ```python from typing import List def custom_sort(arr: List[int]) -> List[int]: ```
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]) -> List[int]: """ Sorts a given list of integers from smallest to largest using the selection sort algorithm. Args: arr (List[int]): The list of integers to b...
python_sharegpt_23k
11,693
Write a Python function to implement a breadth-first search (BFS) algorithm that finds the shortest path between two given vertices in a directed graph. The function should have a space complexity of O(n) and a time complexity of O(V + E), where V is the number of vertices and E is the number of edges in the graph. The...
Here is the Python code to solve the given problem in the markdown block: ```python from collections import deque from typing import Dict, List, Optional, Set def bfs_shortest_path(graph: Dict[str, List[str]], start: str, end: str) -> Optional[List[str]]: """ Find the shortest path between two vertices in a di...
python_sharegpt_23k
11,694
Write a Python function to transform a given list of integers into a dictionary. The dictionary should contain the numbers as keys and their squares as values. The list should not contain any duplicates and should be sorted in ascending order. The dictionary should only include numbers that are divisible by 2 and their...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def transform_list_to_dict(nums: List[int]) -> Dict[int, int]: """ Transforms a given list of integers into a dictionary. The dictionary contains the numbers as keys and their squares as values. ...
python_sharegpt_23k
11,699
Write a Python function to find all prime numbers within a given range [lower_limit, upper_limit]. The function should have a time complexity of O(n * sqrt(m)), where n is the number of elements in the range and m is the average value of the range. The function should also use a space complexity of O(n), where n is the...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. ""...
python_sharegpt_23k
11,700
Write a Python function to find the longest common prefix among a list of strings. The function should have a time complexity of O(n*m), where n is the number of strings in the list and m is the length of the longest string. The function should not use any built-in string matching functions (such as `startswith` or `su...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def longest_common_prefix(strs: List[str]) -> str: """ Find the longest common prefix among a list of strings. Args: strs (List[str]): A list of strings to find the longest common prefix fro...
python_sharegpt_23k
11,711
Write a Python function to normalize a given text string for natural language processing, considering the impact of multilingual data and the requirement for handling linguistic variations and irregularities. The function should perform the following steps: 1. Convert all characters to lowercase. 2. Remove all punctuat...
Here is the Python code to solve the given problem in the markdown block: ```python import string def normalize_text(text: str) -> str: """ Normalizes a given text string for natural language processing by performing the following steps: 1. Convert all characters to lowercase. 2. Remove all punctuation...
python_sharegpt_23k
11,712
Write a Python function to check whether a given list of integers contains at least one prime number. If a prime number is found, the function should return "Prime number found". If no prime number is found, the function should return "No prime number found". The code should start with: ```python from typing import Li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def check_for_prime(numbers: List[int]) -> str: """ Check whether the given list of integers contains at least one prime number. Args: numbers (List[int]): The list of integers to check for ...
python_sharegpt_23k
11,716
Write a Python function to determine if a given string is a palindrome. The function should be case-sensitive and should have a time complexity of O(n), where n is the length of the input string. The function should return `True` if the string is a palindrome and `False` otherwise. The code should start with: ```pytho...
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(s: str) -> bool: """ Determine if a given string is a palindrome. This function checks if the input string reads the same forwards and backwards. The function is case-sensitive, meaning "Racecar" is no...
python_sharegpt_23k
11,717
Write a Python function to retrieve the value associated with a given key from a JSON-like dictionary. The function should support nested keys, where a key can contain dots to represent nesting levels in the JSON data. If the key does not exist in the JSON data, the function should return `None`. The function should al...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, Dict def get_nested_value(json_data: Dict[str, Any], key: str) -> Any: """ Retrieve the value associated with a given key from a JSON-like dictionary. Supports nested keys using dot notation. Ar...
python_sharegpt_23k
11,718
Write a Python function to determine if a given number is prime and use this function within a loop to print all the prime numbers between 1 and a specified upper limit. The function should start with: ```python def is_prime(num: int) -> bool: ``` The loop to print prime numbers should start with: ```python def print_p...
Here is the Python code to solve the given problem in the markdown block: ```python def is_prime(num: int) -> bool: """ Determine if a given number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. """ if ...
python_sharegpt_23k
11,728
Write a Python function to process a list of floating-point numbers and return a tuple containing the sorted list of integers in descending order and the sum of all the elements in the sorted list. The function should handle the conversion of floating-point numbers to integers and ensure the list is sorted correctly. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def process_float_data(x_data: List[float]) -> Tuple[List[int], int]: """ Process a list of floating-point numbers and return a tuple containing the sorted list of integers in descending order and...
python_sharegpt_23k
11,731
Write a Python function to find the two largest numbers in a given list of integers. The function should have a time complexity of O(n) and should not use any built-in sorting functions or additional data structures to store intermediate values. The function should iterate through the list only once and should not modi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple, Union def find_two_largest(numbers: List[int]) -> Union[Tuple[int, int], str]: """ Find the two largest numbers in a given list of integers. Args: numbers (List[int]): The list of in...
python_sharegpt_23k
11,734
Write a Python function to perform the Caesar Cipher encryption on a given string of text using a specified key. The Caesar Cipher involves shifting each letter in the text by a certain number of positions down the alphabet. The function should handle both uppercase and lowercase letters, and non-alphabetical character...
Here is the Python code to solve the given problem in the markdown block: ```python def caesar_cipher(text: str, key: int) -> str: """ Encrypts the given text using the Caesar Cipher technique with the specified key. Args: text (str): The text to be encrypted. key (int): The number of posit...
python_sharegpt_23k
11,735
Write a Python function to find and return a list of all prime numbers between 1 and a given number `n` (inclusive), but only if the number is not divisible by 3. The function should start with: ```python from typing import List def prime_numbers_not_divisible_by_3(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def prime_numbers_not_divisible_by_3(n: int) -> List[int]: """ Returns a list of prime numbers between 1 and n (inclusive) that are not divisible by 3. Args: n (int): The upper l...
python_sharegpt_23k
11,740
Write a Python function to find the median of an array of n numbers, where n is an odd number and the numbers are all unique and positive integers. The function should return the median value. The code should start with: ```python from typing import List def find_median_of_array(arr: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List def find_median_of_array(arr: List[int]) -> int: """ Finds the median of an array of n numbers, where n is an odd number and the numbers are all unique and positive integers. Args: arr (Li...
python_sharegpt_23k
11,741
Write a Python function to find the top three most common words in a given string, excluding common stop words and words shorter than three characters. The function should handle words separated by punctuation marks or special characters and return a list of tuples containing the top three most common words and their f...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import re from collections import Counter def find_top_three_common_words(string: str) -> List[Tuple[str, int]]: """ Finds the top three most common words in a given string, excluding common stop ...
python_sharegpt_23k
11,753
Write a Python function to print out all the elements of a given 2D array in a spiral order. The array can have varying dimensions, but it will always be a square matrix (n x n). The spiral order starts from the top-left corner and goes clockwise. The code should start with: ```python from typing import List def prin...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_spiral_order(matrix: List[List[int]]) -> None: """ Prints the elements of a given 2D array in a spiral order. Args: matrix (List[List[int]]): The 2D array (square matrix) to be pri...
python_sharegpt_23k
11,755
Write a Python function to concatenate two lists in alternating order without using the "+" operator or the "extend" method. The resulting list should contain the elements of both lists in alternating order. If one list is longer than the other, the remaining elements of the longer list should be appended to the end of...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def concatenate_alternating(list1: List[int], list2: List[int]) -> List[int]: """ Concatenate two lists in alternating order without using the "+" operator or the "extend" method. Args: list...
python_sharegpt_23k
11,758
Write a Python function to calculate the sum of the elements in each row of a given 2-dimensional array. The array can have a variable number of rows and columns, and the elements are integers ranging from -10^9 to 10^9. The total number of elements in the array can be as large as 10^6. The solution should have a time ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def row_sums(arr: List[List[int]]) -> List[int]: """ Calculate the sum of the elements in each row of a given 2-dimensional array. Args: arr (List[List[int]]): A 2-dimensional array (list of...
python_sharegpt_23k
11,761
Write a Python function to find and return the prime factors of a given number in ascending order. The function should handle any positive integer input and return a list of its prime factors. The code should start with: ```python from typing import List def prime_factors(number: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def prime_factors(number: int) -> List[int]: """ Find and return the prime factors of a given number in ascending order. Args: number (int): The number for which to find the prime factors. ...
python_sharegpt_23k
11,762
Write a Python function to add two integers without using any arithmetic operators, bitwise operators, or any other mathematical operations (such as multiplication, division, etc.). The function should use recursion to achieve the addition. The code should start with: ```python def add_without_operators(a: int, b: int...
Here is the Python code to solve the given problem in the markdown block: ```python def add_without_operators(a: int, b: int) -> int: """ Adds two integers without using any arithmetic operators, bitwise operators, or any other mathematical operations. Args: a (int): The first integer. b (i...
python_sharegpt_23k
11,766
Write a Python function to implement a binary search algorithm that finds the first occurrence of a target element in a sorted array. If the target element is not found, the function should return -1. The input array will not be empty. The code should start with: ```python from typing import List def find_first_occur...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_first_occurrence(arr: List[int], target: int) -> int: """ Finds the first occurrence of a target element in a sorted array using binary search. Args: arr (List[int]): A sorted list ...
python_sharegpt_23k
11,768
Write a Python function to find the second minimum value in an unsorted array of integers without using any built-in sorting functions or data structures. The function should have a time complexity of O(n) and a space complexity of O(1). The code should start with: ```python from typing import List, Optional def find...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_second_minimum(nums: List[int]) -> Optional[int]: """ Find the second minimum value in an unsorted array of integers. Args: nums (List[int]): The unsorted array of integer...
python_sharegpt_23k
11,774
Write a Python function to generate a list of odd numbers within a specified range [start, end]. The function should use a while loop to ensure that only odd numbers are included in the list. The function should start with: ```python from typing import List def generate_odd_numbers(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 generate_odd_numbers(start: int, end: int) -> List[int]: """ Generate a list of odd numbers within the specified range [start, end]. Args: start (int): The starting value of the range ...
python_sharegpt_23k
11,779
Write a Python function to find the indices of the first occurrence of any two consecutive elements in a given array that are equal to a specified value. If no such pair exists, the function should return `None`. The input array will have at least three elements, and the specified value will be an integer. The code sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Optional def find_consecutive_pairs(arr: List[int], value: int) -> Optional[List[int]]: """ Find the indices of the first occurrence of any two consecutive elements in the array that are equal to the sp...
python_sharegpt_23k
11,782
Write a Python function to calculate the sum of the digits of a given integer and then print each digit of the resulting sum individually. The function should handle both positive and negative integers. The code should start with: ```python def sum_of_digits_and_print(val: int) -> None: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_digits_and_print(val: int) -> None: """ Calculate the sum of the digits of a given integer and print each digit of the resulting sum individually. Args: val (int): The integer whose digits' sum needs to b...
python_sharegpt_23k
11,787
Write a Python function to generate an m x n matrix of random numbers between a specified lower and upper bound, rounded to a specified number of decimal places. The function should accept the number of rows `m`, the number of columns `n`, the lower bound `lower_bound`, the upper bound `upper_bound`, and the number of ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_random_matrix(m: int, n: int, lower_bound: float, upper_bound: float, decimal_places: int) -> List[List[float]]: """ Generate an m x n matrix of random numbers between a specif...
python_sharegpt_23k
11,795
Write a Python function to modify each element of a given array by multiplying it by a constant value. If the constant value is 0, set all elements of the array to 0. If the constant value is negative, reverse the order of the array elements after the modification. Return the modified array. 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 modify_array(arr: List[int], constant: int) -> List[int]: """ Modify each element of the given array by multiplying it by a constant value. If the constant value is 0, set all elements of the arr...
python_sharegpt_23k
11,796
Write a Python function to merge two sorted arrays of prime numbers in ascending order while removing duplicates and maintaining the original order of the elements. The merged array should have no more than twice the length of the original arrays. Additionally, the merged array should be sorted in descending order. The...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_prime_arrays(arr1: List[int], arr2: List[int]) -> List[int]: """ Merge two sorted arrays of prime numbers in ascending order while removing duplicates and maintaining the original order. Th...
python_sharegpt_23k
11,800
Write a Python function that takes a string as input and returns the same string, but with all occurrences of the word "bold" wrapped in a `<strong>` HTML tag. The function should handle cases where the word "bold" appears at the beginning of a sentence, in the middle, or at the end, and should not wrap substrings that...
Here is the Python code to solve the given problem in the markdown block: ```python import re def wrap_bold_tags(input_string: str) -> str: """ Wraps all occurrences of the word "bold" in the input string with <strong> HTML tags. Args: input_string (str): The input string to be processed. Ret...
python_sharegpt_23k
11,801
Write a Python function to generate a list of n random integers between a specified range [min_val, max_val], calculate the average of these numbers, and return the average rounded to the nearest integer. The function should use list comprehension to generate the random numbers and should not exceed a time complexity o...
Here is the Python code to solve the given problem in the markdown block: ```python import random from typing import List def generate_random_numbers_and_average(n: int, min_val: int, max_val: int) -> int: """ Generates a list of n random integers between min_val and max_val, calculates the average, and return...
python_sharegpt_23k
11,802
Write a Python function to combine two lists into a single list containing each element of both lists in order. The combined list should be sorted in ascending order. The input lists may contain duplicate elements. The code should start with: ```python from typing import List def combine_and_sort_lists(list_first: Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def combine_and_sort_lists(list_first: List[int], list_second: List[int]) -> List[int]: """ Combines two lists into a single list and sorts it in ascending order. Args: list_first (List[int]...
python_sharegpt_23k
11,807
Write a Python function to insert an integer into a sorted array of integers while maintaining the sorted order. The function should return the modified array. The code should start with: ```python from typing import List def insert_into_sorted_array(arr: List[int], num: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def insert_into_sorted_array(arr: List[int], num: int) -> List[int]: """ Inserts an integer into a sorted array of integers while maintaining the sorted order. Args: arr (List[int]): The sor...
python_sharegpt_23k
11,809
Write a Python function to format the current date and time in the specified format "dd/mm/yyyy hh:mm:ss". The function should return the formatted string. Additionally, provide a piece of erroneous code that attempts to display the date and time in the incorrect format "mm/dd/yyyy hh:mm:ss" and explain why it is incor...
Here is the Python code to solve the given problem in the markdown block: ```python import datetime def format_current_datetime() -> str: """ Formats the current date and time in the specified format "dd/mm/yyyy hh:mm:ss". Returns: str: The formatted date and time string. """ now = datetim...
python_sharegpt_23k
11,810
Write a Python function to classify an integer as "positive", "negative", or "zero" without using any if-else statements or comparison operators. The function should only use bitwise operators and arithmetic operators. The code should start with: ```python def classify_number(num: int) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def classify_number(num: int) -> str: """ Classify an integer as "positive", "negative", or "zero" without using if-else statements or comparison operators. Args: num (int): The integer to classify. Returns: ...
python_sharegpt_23k
11,814
Write a Python function to calculate the sum of all prime numbers in a given array of integers. The function should return the sum of the prime numbers. The code should start with: ```python from typing import List import math def sum_of_primes(array: List[int]) -> int: ```
Here is the Python code to solve the given problem in the markdown block: : ```python from typing import List import math def sum_of_primes(array: List[int]) -> int: """ Calculate the sum of all prime numbers in a given array of integers. Args: array (List[int]): The array of integers to check for...
python_sharegpt_23k
11,815
Write a Python function that iterates over a range of numbers and checks if each number is divisible by both 2 and 3. If the condition is met, the function should return the square of the number; otherwise, it should return the number itself. The function should accept two parameters: the start and end of the range (in...
Here is the Python code to solve the given problem in the markdown block: ```python def process_numbers(start: int, end: int) -> list: """ Process numbers in the given range [start, end] and return a list where each number is either the square of the number (if divisible by both 2 and 3) or the number itself. ...
python_sharegpt_23k
11,824
Write a Python function to insert a given element into a sorted list of integers in ascending order, maintaining the order of the list. If the element already exists in the list, it should be inserted after the last occurrence of the element. The function should return a new list with the element inserted at the correc...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def insert_element(lst: List[int], element: int) -> List[int]: """ Inserts an element into a sorted list of integers in ascending order, maintaining the order of the list. If the element already exis...
python_sharegpt_23k
11,825
Write a Python function to determine whether a given list of integers contains an odd number of odd integers. Additionally, the function should return the count of odd integers present in the list. The code should start with: ```python from typing import List, Tuple def has_odd_number_of_odds(lst: List[int]) -> Tuple...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def has_odd_number_of_odds(lst: List[int]) -> Tuple[int, bool]: """ Determines whether a given list of integers contains an odd number of odd integers. Additionally, it returns the count of od...
python_sharegpt_23k
11,826
Write a Python function to remove any leading and trailing whitespaces from a given string. Additionally, the function should also remove any whitespace characters in between the words of the string. However, the function should handle multiple consecutive whitespace characters between words and replace them with a sin...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_whitespace(string: str) -> str: """ Removes any leading and trailing whitespaces from the given string and replaces multiple consecutive whitespace characters between words with a single space. Args: ...
python_sharegpt_23k
11,828
Write a Python function to sort a list of integers by their absolute values without using any built-in sorting functions or methods, and without using any external libraries or modules. The solution should have a time complexity of O(n^2) or better. The code should start with: ```python from typing import List def sor...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_by_absolute_value(lst: List[int]) -> List[int]: """ Sorts a list of integers by their absolute values without using built-in sorting functions or external libraries. Args: lst (List...
python_sharegpt_23k
11,829
Write a Python function to calculate the sum of all positive integers in a given array of integers. If there are no positive integers, return 0. The solution must have a time complexity of O(n), where n is the length of the array. The code should start with: ```python from typing import List def sum_of_positive_integ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_of_positive_integers(arr: List[int]) -> int: """ Calculate the sum of all positive integers in the given array. Args: arr (List[int]): The array of integers to process. Returns:...
python_sharegpt_23k
11,837
Write a Python function to calculate the square root of a given non-negative integer `x` using a binary search algorithm. The function should have a time complexity of O(log n) and a space complexity of O(1). You are not allowed to use any built-in functions or libraries for calculating the square root. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python def sqrt_binary_search(x: int) -> int: """ Calculate the integer square root of a non-negative integer x using binary search. Args: x (int): The non-negative integer for which to calculate the square root. Retu...
python_sharegpt_23k
11,842
Write a Python function to determine if a given string is a palindrome. The function should ignore case, spaces, and punctuation marks. A palindrome is a string that reads the same forwards and backwards. The code should start with: ```python def is_palindrome(s: str) -> bool: ```
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(s: str) -> bool: """ Determine if a given string is a palindrome, ignoring case, spaces, and punctuation marks. Args: s (str): The input string to check. Returns: bool: True if the str...
python_sharegpt_23k
11,846
Write a Python function to filter out even numbers from a given list of integers, remove any duplicates, and sort the resulting list in descending order. The function should start with: ```python from typing import List def filter_and_sort_even_numbers(lst: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def filter_and_sort_even_numbers(lst: List[int]) -> List[int]: """ Filters out even numbers from the given list, removes duplicates, and sorts the resulting list in descending order. Args: l...
python_sharegpt_23k
11,850
Write a Python function to create a new dictionary with the values squared from an input dictionary. The function should handle cases where the input dictionary may contain non-integer keys and values, and should ignore key-value pairs where the value is negative. If the input dictionary is empty, the function should r...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def square_dict_values(input_dict: Dict[int, int]) -> Dict[int, int]: """ Returns a new dictionary with the values squared from the input dictionary. Args: input_dict (Dict[int, int]): The i...
python_sharegpt_23k
11,854
Write a Python function to remove all duplicates from a given list of positive integers and return a new list without modifying the original list. The order of elements in the output list should be the same as their first occurrence in the input list. 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 remove_duplicates_preserve_order(input_array: List[int]) -> List[int]: """ Removes all duplicates from the input array and returns a new array without modifying the original array. The order of e...
python_sharegpt_23k
11,857
Write a Python function to create a dictionary where the keys are the letters of the alphabet (both lowercase and uppercase) and the values are the product of the ASCII values of the corresponding letters. The function should handle both lowercase and uppercase letters, ensuring that each letter appears only once in th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def create_ascii_product_dict() -> Dict[str, int]: """ Create a dictionary where the keys are the letters of the alphabet (both lowercase and uppercase) and the values are the product of the ASCII va...
python_sharegpt_23k
11,860
Write a Python function to print the vowels in lowercase in reverse order. The function should not return any value but should print the vowels directly to the console. The code should start with: ```python def print_vowels_in_reverse(): ```
Here is the Python code to solve the given problem in the markdown block: ```python def print_vowels_in_reverse(): """ Prints the vowels in lowercase in reverse order. This function does not return any value but prints the vowels directly to the console. Args: None Returns: None ...
python_sharegpt_23k
11,863
Write a Python function to search for the first occurrence of a given number in a sorted array. The function should return the index of the first occurrence of the number if it exists in the array, or -1 if it does not. The algorithm should have a time complexity of O(log n), where n is the length of the array. The fun...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_first_occurrence(arr: List[int], target: int) -> int: """ Searches for the first occurrence of a given number in a sorted array. Args: arr (List[int]): The sorted array to search in...
python_sharegpt_23k
11,864
Write a Python function to calculate the sum of all numbers from 1 to `n` (inclusive) without using any iteration control structures like `for` loop, `while` loop, or recursion. The function should use a mathematical formula to achieve this. The code should start with: ```python def sum_of_numbers(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_numbers(n: int) -> int: """ Calculate the sum of all numbers from 1 to n (inclusive) using a mathematical formula. Args: n (int): The upper limit of the range of numbers to sum. Returns: int:...
python_sharegpt_23k
11,867
Write a Python function to remove duplicate elements from a given list while preserving the order of the elements. The list can contain both integers and strings. The function should have a time complexity of O(n), where n is the length of the list. The code should start with: ```python from typing import List, Union ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def remove_duplicates(arr: List[Union[int, str]]) -> List[Union[int, str]]: """ Removes duplicate elements from a list while preserving the order of the elements. Args: arr (List[Unio...
python_sharegpt_23k
11,869
Write a Python function to find the minimum value in an array and return its index, without using any built-in functions or libraries like `min()` or `sorted()`. The array will only contain positive integers. The function should also return the index of the minimum value in the array. The code should start with: ```py...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_min_value_and_index(arr: List[int]) -> Tuple[int, int]: """ Find the minimum value in an array and return its index. Args: arr (List[int]): The array of positive integers. ...
python_sharegpt_23k
11,872
Write a Python function to convert a given string to an integer. The string will only contain digits and may have a leading '+' or '-' sign. The integer should be within the range of -2^31 to 2^31 - 1. If the string cannot be converted to an integer, return 0. The function should handle edge cases such as empty strings...
Here is the Python code to solve the given problem in the markdown block: ```python def string_to_integer(s: str) -> int: """ Converts a given string to an integer. The string will only contain digits and may have a leading '+' or '-' sign. The integer should be within the range of -2^31 to 2^31 - 1. If the...
python_sharegpt_23k
11,887
Write a Python function to search for a specific key-value pair in a dictionary, but only if the key is a string and the value is a positive integer. The function should return the key-value pair if found, or `None` if not found. The function must be implemented manually without using built-in methods such as `filter` ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict, Tuple, Optional def search_key_value_pair(searchKey: str, object: Dict[str, int]) -> Optional[Tuple[str, int]]: """ Searches for a specific key-value pair in a dictionary where the key is a string and t...
python_sharegpt_23k
11,892
Write a Python function to generate and print all unique permutations of a given list of integers. The function should ensure that each permutation is printed only once, even if the list contains duplicate elements. The function should be implemented using a recursive algorithm and should be optimized to reduce unneces...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def print_unique_permutations(nums: List[int]) -> None: """ Generates and prints all unique permutations of a given list of integers. Args: nums (List[int]): The list of integers to permute....
python_sharegpt_23k
11,895
Write a Python function to repeat a given string `s` for `n` times, ensuring that `n` is a positive integer and `s` is a non-empty string. The function should raise a `ValueError` if these conditions are not met. The code should start with: ```python def repeat_string(n: int, s: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def repeat_string(n: int, s: str) -> str: """ Repeats the given string `s` for `n` times. Args: n (int): The number of times to repeat the string. Must be a positive integer. s (str): The string to be repeat...
python_sharegpt_23k
11,896
Write a Python function to generate a list of the first `n` odd numbers. The function should take an integer `n` as input and return a list containing the first `n` odd numbers. The code should start with: ```python from typing import List def generate_first_n_odds(n: int) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_first_n_odds(n: int) -> List[int]: """ Generate a list of the first n odd numbers. Args: n (int): The number of odd numbers to generate. Returns: List[int]: A list ...
python_sharegpt_23k
11,897
Write a Python function to determine the number of days in a given month and year. The function should handle leap years correctly and raise a `ValueError` if the month or year is not within the specified range. The function should only use built-in Python functions and not rely on any external libraries or modules. T...
Here is the Python code to solve the given problem in the markdown block: ```python def get_num_days(month: int, year: int) -> int: """ Returns the number of days in a given month and year. Args: month (int): The month (1-12). year (int): The year (1-9999). Returns: int: The nu...
python_sharegpt_23k
11,909
Write a Python function to calculate the sum of all values in a given two-dimensional array `arr` of size `m`x`n`. The values in the array are integers, and each value is in the range of -100 to 100, inclusive. The function should handle arrays with dimensions up to 1000x1000. The code should start with: ```python fro...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_2d_array(arr: List[List[int]]) -> int: """ Calculate the sum of all values in a given two-dimensional array. Args: arr (List[List[int]]): A two-dimensional array of integers. Re...
python_sharegpt_23k
11,910
Write a Python function to search for the first occurrence of a specified item in a sorted list and return its index. If the item is not found, return -1. The function should handle lists containing duplicate elements and should have a time complexity of O(log n), where n is the number of elements in the list. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_first_occurrence(arr: List[int], item: int) -> int: """ Searches for the first occurrence of a specified item in a sorted list and returns its index. If the item is not found, returns -1. ...