source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 38,989 | Write a Python function to construct a unified shell script that integrates two subsequent commands. The first command should display the text "FileName: File1". The second command should utilize the `cat` command to display the contents of the file named "File1.txt". The function should return the complete shell scrip... | Here is the Python code to solve the given problem in the markdown block:
```python
def construct_shell_script() -> str:
"""
Constructs a unified shell script that integrates two subsequent commands.
The first command displays the text "FileName: File1".
The second command utilizes the cat command to di... |
evol_instruct_66k | 38,998 | Write a Python function to count the number of occurrences of a given element `x` in a list `y`. The function should be efficient and handle various edge cases, such as an empty list or the element not being present in the list. The code should start with:
```python
from typing import List
def count_occurrences(y: Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_occurrences(y: List[int], x: int) -> int:
"""
Counts the number of occurrences of a given element `x` in a list `y`.
Args:
y (List[int]): The list of integers in which to count the... |
evol_instruct_66k | 39,014 | Write a Python function to find the first and last occurrence of a specific target value in a sorted list using binary search. The function should return a list containing the indices of the first and last occurrence of the target value. If the target value is not found in the list, the function should return `[-1, -1]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_first_last_occurrence(lst: List[int], target: int) -> List[int]:
"""
Find the first and last occurrence of a target value in a sorted list using binary search.
Args:
lst (List[int])... |
evol_instruct_66k | 39,018 | Write a Python function to reverse the contents of a given array in place. The function should modify the original array and return it. The code should start with:
```python
from typing import List
def reverse_array(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 reverse_array(arr: List[int]) -> List[int]:
"""
Reverses the contents of a given array in place and returns the modified array.
Args:
arr (List[int]): The array to be reversed.
Re... |
evol_instruct_66k | 39,029 | Write a Python function to determine whether a given integer or a list of integers is a prime number, and also count the number of primes related to each integer. The function should return a tuple for each integer where the first element is the integer, the second element is a boolean indicating whether the integer is... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def init_prime_sieve(n: int) -> List[bool]:
"""
Generate a list of boolean values indicating whether each number up to n is prime.
Args:
n (int): The upper limit for the sieve.
R... |
evol_instruct_66k | 39,035 | Write a Python function to perform elementwise addition of two arrays of the same size. The function should take two lists of integers as input and return a new list containing the sum of corresponding elements from each input list. The code should start with:
```python
from typing import List
def elementwise_addition... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def elementwise_addition(arr1: List[int], arr2: List[int]) -> List[int]:
"""
Perform elementwise addition of two arrays of the same size.
Args:
arr1 (List[int]): The first array of integers.... |
evol_instruct_66k | 39,037 | Write a Python function to create a hierarchical dictionary from two given lists: one containing unique keys and the other containing corresponding values. The function should ensure that the hierarchical dictionary is correctly structured and populated with the provided keys and values. The code should start with:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_hierarchical_dict(keys: List[str], values: List[int]) -> Dict[str, int]:
"""
Creates a hierarchical dictionary from two lists: one containing unique keys and the other containing corresp... |
evol_instruct_66k | 39,053 | Write a Python function to filter a list based on a given predicate function. The function should return a new list containing only the elements from the original list that satisfy the predicate. The code should start with:
```python
from typing import List, Callable
def filter_list_by_predicate(lst: List[int], pred: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable
def filter_list_by_predicate(lst: List[int], pred: Callable[[int], bool]) -> List[int]:
"""
Filters a list based on a given predicate function.
Args:
lst (List[int]): The list of i... |
evol_instruct_66k | 39,056 | Write a Python function that processes a list of strings, where each string may represent a number in binary, octal, decimal, or hexadecimal format. The function should:
1. Convert valid number representations to their decimal (base 10) equivalents.
2. Identify and report invalid number representations that cannot be c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def convert_to_decimal(numbers: List[str]) -> Tuple[List[int], List[str]]:
"""
Converts a list of strings representing numbers in various bases to their decimal equivalents.
Identifies and rep... |
evol_instruct_66k | 39,057 | 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 a different word or phrase, typically using all the original letters exactly once. The function should return `True` if the two strings are anagrams, and `False` othe... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_anagrams(str1: str, str2: str) -> bool:
"""
Determine if two given strings are anagrams of each other.
Args:
str1 (str): The first string to compare.
str2 (str): The second string to compare.
Re... |
evol_instruct_66k | 39,068 | Write a Python function to traverse a multi-layered dictionary and return the aggregate sum of all numerical values within the dictionary. The dictionary may contain nested dictionaries, and the function should handle any depth of nesting. The function should start with:
```python
from typing import Union
def sum_nume... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Union
def sum_numerical_values(dictionary: dict) -> Union[int, float]:
"""
Traverse a multi-layered dictionary and return the sum of all numerical values within.
Args:
dictionary (dict): The dict... |
evol_instruct_66k | 39,081 | Write a Python function to validate a list of email addresses using a regular expression. The function should return two lists: one containing valid email addresses and the other containing invalid email addresses. The regular expression should be designed to match commonly used email formats, including both local and ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import re
def validate_emails(emails: List[str]) -> Tuple[List[str], List[str]]:
"""
Validates a list of email addresses using a regular expression and returns two lists:
one containing valid ... |
evol_instruct_66k | 39,095 | Write a Python function to compare two sequences element-wise and return a list of strings indicating whether each corresponding element in the first sequence is greater than, less than, or equal to the corresponding element in the second sequence. The sequences are lists of integers.
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
def compare_sequences(sequence1: List[int], sequence2: List[int]) -> List[str]:
"""
Compare two sequences element-wise and return a list of strings indicating the comparison results.
Args:
s... |
evol_instruct_66k | 39,099 | Write a Python function to find all valid triplets (country_name, capital, population) from a given list of dictionaries. Each dictionary represents a country and contains the keys 'country_name', 'capital', and 'population'. The function should return a list of tuples, where each tuple contains a valid triplet (countr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict, Tuple
def find_valid_triplets(countries: List[Dict[str, str]]) -> List[Tuple[str, str, int]]:
"""
Find all valid triplets (country_name, capital, population) from a given list of dictionaries.
... |
evol_instruct_66k | 39,109 | Write a Python function to sort a given list using the insertion sort algorithm. The function should modify the list in place and return the sorted list. The code should start with:
```python
from typing import List
def insertion_sort(unsorted_list: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def insertion_sort(unsorted_list: List[int]) -> List[int]:
"""
Sorts the given list using the insertion sort algorithm.
Args:
unsorted_list (List[int]): The list of integers to be sorted.
... |
evol_instruct_66k | 39,114 | Write a Python function to find the longest substring in a given string that does not contain any repeating characters. The function should return the length of this longest substring.
The code should start with:
```python
def longest_substring_without_repeating_characters(s: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def longest_substring_without_repeating_characters(s: str) -> int:
"""
Find the length of the longest substring without repeating characters.
Args:
s (str): The input string to search for the longest substring.
... |
evol_instruct_66k | 39,116 | Write a Python function to derive the occurrence count and the position of the first occurrence of each distinct numerical component in a given integer sequence. The function should return two dictionaries: one for the occurrence count and one for the first occurrence position.
The code should start with:
```python
fr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def count_occurrences_and_first_positions(lst: List[int]) -> (Dict[int, int], Dict[int, int]):
"""
Derive the occurrence count and the position of the first occurrence of each distinct numerical co... |
evol_instruct_66k | 39,117 | Write a Python function to manage a roster of individuals and their corresponding email addresses using a dictionary. The function should allow adding, retrieving, removing, and checking the presence of individuals in the roster. The code should start with:
```python
from typing import Dict, Optional
def manage_roster... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Optional
def manage_roster(roster: Dict[str, str], action: str, name: Optional[str] = None, email: Optional[str] = None) -> Optional[Dict[str, str]]:
"""
Manages a roster of individuals and their email ... |
evol_instruct_66k | 39,119 | Write a Python function to demonstrate the concept of call by value and call by reference using lists. The function should take a list as an argument and modify its contents. Additionally, write a function to demonstrate call by value using integers. The code should start with:
```python
from typing import List
def mo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def modify_list_by_reference(lst: List[int]) -> None:
"""
Modify the list in place by appending the sum of its elements.
Args:
lst (List[int]): The list to be modified.
Returns:
... |
evol_instruct_66k | 39,129 | Write a Python function to iterate through a given list of integers and print each element. For each element, calculate the division of the next element by the current element and print the result. Handle potential exceptions such as `ZeroDivisionError` and `IndexError` gracefully. The function should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def process_array(numbers: List[int]) -> None:
"""
Iterates through a list of integers, prints each element, and calculates the division of the next element by the current element.
Handles exceptions... |
evol_instruct_66k | 39,130 | Write a Python function to flatten a nested dictionary. The function should take a dictionary and an optional separator string as input and return a flattened dictionary where the keys are concatenated with the separator. The default separator should be an underscore (`_`).
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 Dict, Any
def flatten_nested_dict(nested_dict: Dict[str, Any], separator: str = '_') -> Dict[str, Any]:
"""
Flattens a nested dictionary into a single-level dictionary.
Args:
nested_dict (Dict[st... |
evol_instruct_66k | 39,133 | Write a Python function to eliminate all occurrences of multiple spaces (two or more consecutive spaces) in a given text string and replace them with a single space. The function should handle any number of consecutive spaces, ensuring that the resulting text contains only single spaces between words.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def eliminate_multiple_spaces(text: str) -> str:
"""
Eliminates all occurrences of multiple spaces (two or more consecutive spaces) in a given text string and replaces them with a single space.
Args:
text... |
evol_instruct_66k | 39,134 | Write a Python function to find the longest common subsequence (LCS) between two given strings. The function should return the length of the LCS.
The code should start with:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def longest_common_subsequence(str1: str, str2: str) -> int:
"""
Calculate the length of the longest common subsequence (LCS) between two strings.
Args:
str1 (str): The first string.
str2 (str): The second s... |
evol_instruct_66k | 39,138 | Write a Python function to generate a list of prime numbers within a given range `[start, end]`. The function should return a list of all prime numbers that fall within the specified range. The function should be efficient and handle edge cases such as when the range is invalid or when there are no prime numbers within... | 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.
... |
evol_instruct_66k | 39,140 | Write a Python function to calculate the average marks of students from a given dictionary containing student names and their corresponding marks. The function should handle cases where the dictionary might be empty.
The code should start with:
```python
from typing import Dict
def calculate_average_marks(student_mar... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def calculate_average_marks(student_marks: Dict[str, int]) -> float:
"""
Calculate the average marks of students from a given dictionary containing student names and their corresponding marks.
Args:... |
evol_instruct_66k | 39,143 | Write a Python function to iterate through a given list and print each element using a `while` loop instead of a `for` loop. The function should take a list of integers as input and print each element on a new line.
The code should start with:
```python
from typing import List
def print_elements_with_while_loop(arr: ... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def print_elements_with_while_loop(arr: List[int]) -> None:
"""
Iterates through a given list of integers and prints each element using a while loop.
Args:
arr (List[int]): The list of int... |
evol_instruct_66k | 39,154 | Write a Python function to detect plagiarism between multiple documents using a hash algorithm. The function should take a list of documents and return a list of tuples where each tuple contains the indices of two documents that are detected as plagiarized. The function should use the SHA256 hash algorithm to compare t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import hashlib
def detect_plagiarism(documents: List[str]) -> List[Tuple[int, int]]:
"""
Detects plagiarism among multiple documents using the SHA256 hash algorithm.
Args:
documents (... |
evol_instruct_66k | 39,157 | Write a Python function to create a three-dimensional matrix of given dimensions, where every element in the matrix is initialized to a specified value. The function should return the constructed matrix.
The code should start with:
```python
from typing import List
def create_3d_matrix(dimensions: List[int], initial_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def create_3d_matrix(dimensions: List[int], initial_value: int) -> List[List[List[int]]]:
"""
Creates a three-dimensional matrix with the specified dimensions and initializes all elements to the given va... |
evol_instruct_66k | 39,163 | Write a Python function to calculate the sum of all numeric elements in a given list. The function should handle lists containing integers, floats, and nested lists of integers and floats. The function should return the total sum of all numeric elements.
The code should start with:
```python
from typing import List, U... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Union
def sum_nested_array(arr: List[Union[int, float, List]]) -> Union[int, float]:
"""
Calculate the sum of all numeric elements in a given list, including nested lists.
Args:
arr (List... |
evol_instruct_66k | 39,164 | Write a Python function to find all words that start with 'cat' in a given text, ensuring that the function also matches 'cat' when it appears after punctuation marks. The function should be case-insensitive.
The code should start with:
```python
import re
from typing import List
def find_cat_words(text: str) -> List... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from typing import List
def find_cat_words(text: str) -> List[str]:
"""
Find all words in the text that start with 'cat', including those that appear after punctuation marks.
Args:
text (str): The input t... |
evol_instruct_66k | 39,168 | Write a Python function to determine if two given strings are permutations of each other, i.e., they contain the same characters in different orders. The function should be case-insensitive and should ignore any non-alphabetic characters. The function should start with:
```python
def are_permutations(string1: str, stri... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_permutations(string1: str, string2: str) -> bool:
"""
Determine if two strings are permutations of each other, ignoring case and non-alphabetic characters.
Args:
string1 (str): The first string to compare.
... |
evol_instruct_66k | 39,171 | Write a Python function to implement the Bubble Sort algorithm, which sorts an array in ascending order. The function should correctly handle the sorting process and return the sorted array. The code should start with:
```python
from typing import List
def bubble_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 bubble_sort(arr: List[int]) -> List[int]:
"""
Sorts an array in ascending order using the Bubble Sort algorithm.
Args:
arr (List[int]): The array to be sorted.
Returns:
List... |
evol_instruct_66k | 39,174 | Write a Python function to filter out empty strings and strings consisting solely of whitespace from a given list of strings. The function should return a new list containing only the non-empty and non-whitespace strings. The code should start with:
```python
from typing import List
def filter_non_empty_strings(string... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_non_empty_strings(string_list: List[str]) -> List[str]:
"""
Filters out empty strings and strings consisting solely of whitespace from a given list of strings.
Args:
string_list (... |
evol_instruct_66k | 39,176 | Write a Python function to convert a given string to its uppercase representation. The function should handle any string input, including empty strings and strings with mixed case characters. The function should return the uppercase version of the input string.
The code should start with:
```python
def convert_to_uppe... | Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_uppercase(input_str: str) -> str:
"""
Converts the given string to its uppercase representation.
Args:
input_str (str): The string to be converted to uppercase.
Returns:
str: The uppercas... |
evol_instruct_66k | 39,183 | Write a Python function to reverse a given string without using any built-in functions or additional variables. The function should work for both ASCII and Unicode characters. The code should start with:
```python
def reverse_string(string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(string: str) -> str:
"""
Reverses a given string without using any built-in functions or additional variables.
Args:
string (str): The input string to be reversed.
Returns:
str: The r... |
evol_instruct_66k | 39,186 | Write a Python function that translates a given Laplacian matrix of an unweighted, directed graph into its equivalent adjacency list representation. The function should also validate the Laplacian matrix using the Gershgorin circle theorem to ensure it corresponds to a valid directed graph. If the Laplacian matrix is i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def laplacian_to_adjacency_list(laplacian: List[List[float]]) -> Dict[int, List[int]]:
"""
Converts a given Laplacian matrix of an unweighted, directed graph into its equivalent adjacency list repr... |
evol_instruct_66k | 39,190 | Write a Python function to reverse engineer a URL slug back into its original, unmodified string formation. The URL slug may contain multiple words separated by hyphens. The function should handle various cases such as multiple hyphens, leading/trailing hyphens, and mixed case letters. The function should also capitali... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_slug(slug: str) -> str:
"""
Reverse engineers a URL slug back into its original, unmodified string formation.
Args:
slug (str): The URL slug to be reversed.
Returns:
str: The original string... |
evol_instruct_66k | 39,210 | Write a Python function to sort a given list of integers using the insertion sort algorithm. The function should return the sorted list. The code should start with:
```python
from typing import List
def insertion_sort(array: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def insertion_sort(array: List[int]) -> List[int]:
"""
Sorts a list of integers using the insertion sort algorithm.
Args:
array (List[int]): The list of integers to be sorted.
Returns:
... |
evol_instruct_66k | 39,212 | Write a Python function to check if a given integer `x` is equal to a specified value `target`. If `x` is equal to `target`, the function should print a message indicating that `x` is equal to `target`. Otherwise, it should print a message indicating that `x` is not equal to `target`.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_equality(x: int, target: int) -> None:
"""
Checks if the given integer `x` is equal to the specified `target` value.
If `x` is equal to `target`, it prints a message indicating that `x` is equal to `target`.
Ot... |
evol_instruct_66k | 39,216 | Write a Python function to analyze the provided Python code snippet and determine the specific type of loop being utilized. Modify the code to use a different type of loop to achieve the same result. The function should return a string describing the original loop type and the modified loop type. Additionally, the func... | Here is the Python code to solve the given problem in the markdown block:
```python
def analyze_and_modify_loop() -> str:
"""
Analyzes the provided Python code snippet to determine the type of loop used,
modifies the loop to use a different type, and prints the numbers from 0 to 9.
Returns:
str... |
evol_instruct_66k | 39,217 | Write a Python function to remove recurring characters from a given alphanumeric string while preserving the order of their first occurrence. The function should efficiently handle the input string and return the resulting string with duplicates removed.
The code should start with:
```python
from collections import Or... | Here is the Python code to solve the given problem in the markdown block:
```python
from collections import OrderedDict
def remove_duplicates(s: str) -> str:
"""
Removes recurring characters from the given alphanumeric string while preserving the order of their first occurrence.
Args:
s (str): The... |
evol_instruct_66k | 39,221 | Write a Python function to generate a social media post with a title, content, and a list of tags. The function should return a dictionary representing the post. The dictionary should have the following keys: 'title', 'content', and 'tags'. The 'tags' value should be a list of strings. The function should also ensure t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_social_media_post(title: str, content: str, tags: List[str]) -> Dict[str, object]:
"""
Creates a social media post represented as a dictionary.
Args:
title (str): The title ... |
evol_instruct_66k | 39,223 | Write a Python function to factorize a given string input into its prime factors. The function should convert the string to a whole number, factorize it into prime numbers, and return an array of the prime factors in ascending order.
The code should start with:
```python
from typing import List
def factorize_string_t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def factorize_string_to_primes(s: str) -> List[int]:
"""
Factorizes a given string input into its prime factors.
Args:
s (str): The input string to be converted and factorized.
Returns:... |
evol_instruct_66k | 39,234 | Write a Python function to create a dictionary where the keys are sequential integers from 1 to `n` (inclusive), and each key is mapped to its square root. The function should use dictionary comprehension for efficiency.
The code should start with:
```python
from typing import Dict
import math
def generate_square_roo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
import math
def generate_square_roots_dict(n: int) -> Dict[int, float]:
"""
Generates a dictionary where the keys are sequential integers from 1 to n (inclusive),
and each key is mapped to its square... |
evol_instruct_66k | 39,247 | Write a Python function to compute the scalar product of two given arrays `a` and `b`, and store the result in a third array `c`. The function should ensure that the input arrays `a` and `b` are of the same length. If they are not, the function should raise a `ValueError`. The function 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 scalar_product(a: List[int], b: List[int]) -> List[int]:
"""
Compute the scalar product of two arrays `a` and `b`, and store the result in array `c`.
Args:
a (List[int]): The first input... |
evol_instruct_66k | 39,253 | Write a Python function to sort a list of numbers in ascending order using the bubble sort algorithm. The function should handle various edge cases, such as an empty list, a list with a single element, and a list with duplicate elements. The function should also ensure that all elements in the list are numbers (either ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def bubble_sort(x: List[Union[int, float]]) -> List[Union[int, float]]:
"""
Sorts a list of numbers in ascending order using the bubble sort algorithm.
Args:
x (List[Union[int, float]... |
evol_instruct_66k | 39,255 | Write a Python function to determine if a given sentence is a permutation of the aphorism "You can't judge a book by its cover", considering variations in case sensitivity and syntactic symbols. The function should return `True` if the sentence is a permutation of the aphorism, and `False` otherwise.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
from collections import Counter
def is_permutation_of_aphorism(sentence: str) -> bool:
"""
Determines if the given sentence is a permutation of the aphorism "You can't judge a book by its cover".
Args:
se... |
evol_instruct_66k | 39,257 | Write a Python function to compute the cumulative total of a collection of integer values. The function should take a list of integers as input and return a list of cumulative totals, where each element in the output list is the sum of all previous elements in the input list plus the element itself.
The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def compute_cumulative_totals(int_list: List[int]) -> List[int]:
"""
Computes the cumulative total of a collection of integer values.
Args:
int_list (List[int]): A list of integers for which... |
evol_instruct_66k | 39,263 | Write a Python function to remove duplicate elements from a given array while maintaining the relative order of elements and without using built-in methods or extra space. The function should have an O(n) time complexity. The code should start with:
```python
from typing import List
def remove_duplicates(arr: List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates(arr: List[int]) -> List[int]:
"""
Removes duplicate elements from the given array while maintaining the relative order of elements.
The function operates in O(n) time complexity... |
evol_instruct_66k | 39,284 | Write a Python function to perform element-wise multiplication of two matrices using the `numpy` library. The function should take two matrices as input and return the resulting matrix after element-wise multiplication. The code should start with:
```python
import numpy as np
from typing import List
def element_wise_m... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
from typing import List
def element_wise_matrix_multiplication(matrix1: List[List[int]], matrix2: List[List[int]]) -> List[List[int]]:
"""
Perform element-wise multiplication of two matrices.
Args:
... |
evol_instruct_66k | 39,288 | Write a Python function to convert a binary number represented as a string to its decimal (base 10) equivalent. The function should handle binary strings of any length and should return the decimal representation of the given binary number.
The code should start with:
```python
def binary_to_decimal(binary: str) -> in... | Here is the Python code to solve the given problem in the markdown block:
```python
def binary_to_decimal(binary: str) -> int:
"""
Convert a binary number represented as a string to its decimal (base 10) equivalent.
Args:
binary (str): The binary number to convert, represented as a string of '0's a... |
evol_instruct_66k | 39,291 | Write a Python function to determine if two given strings are isomorphic. Two strings are considered isomorphic if there is a one-to-one mapping possible for every character of the first string to every character of the second string. The function should return `True` if the strings are isomorphic and `False` otherwise... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_isomorphic(str1: str, str2: str) -> bool:
"""
Determines if two strings are isomorphic.
Args:
str1 (str): The first string to check.
str2 (str): The second string to check.
Returns:
bool... |
evol_instruct_66k | 39,296 | Write a Python function to determine if a given number is even or odd. The function should return a string "Even" if the number is even, and "Odd" if the number is odd. The code should start with:
```python
def check_even_or_odd(number: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def check_even_or_odd(number: int) -> str:
"""
Determines if a given number is even or odd.
Args:
number (int): The number to check.
Returns:
str: "Even" if the number is even, "Odd" if the number is od... |
evol_instruct_66k | 39,300 | Write a Python function to calculate the Levenshtein distance between two strings. The Levenshtein distance is a measure of the difference between two sequences, defined as the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other.
The code shou... | 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... |
evol_instruct_66k | 39,325 | Write a Python function to count the number of distinct lexemes in a given text string. A lexeme is defined as a sequence of alphanumeric characters (letters and digits) that are separated by non-alphanumeric characters. The function should return the count of unique lexemes found in the text string.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def count_distinct_lexemes(text_string: str) -> int:
"""
Count the number of distinct lexemes in a given text string.
A lexeme is defined as a sequence of alphanumeric characters (letters ... |
evol_instruct_66k | 39,328 | Write a Python function to determine if a given string is a pangram without using any built-in Python set functions or data structures. A pangram is a sentence that contains every letter of the alphabet at least once. The function should ignore case and non-alphabetic characters.
The code should start with:
```python
... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_pangram(input_str: str) -> bool:
"""
Determine if the given string is a pangram.
A pangram is a sentence that contains every letter of the alphabet at least once.
This function ignores case and non-alphabetic cha... |
evol_instruct_66k | 39,341 | Write a Python function to convert a given decimal number to its hexadecimal representation. The function should handle both positive and negative integers. The hexadecimal representation should be returned as a string without the '0x' prefix.
The code should start with:
```python
def decimal_to_hex(n: int) -> str:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def decimal_to_hex(n: int) -> str:
"""
Converts a given decimal number to its hexadecimal representation.
Args:
n (int): The decimal number to be converted.
Returns:
str: The hexadecimal representation ... |
evol_instruct_66k | 39,343 | Write a Python function to analyze a list of text sequences and create a dictionary that contains the frequency of each distinct word along with the sentences in which they appear. The function should handle case insensitivity and remove punctuation from the words. The code should start with:
```python
from typing impo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
from collections import defaultdict
def word_frequency_and_sentences(texts: List[str]) -> Dict[str, Dict[str, List[str]]]:
"""
Analyzes a list of text sequences and creates a dictionary containing ... |
evol_instruct_66k | 39,352 | Write a Python function to calculate the sum of the squares of the first n odd numbers. The function should take an integer `n` as input and return the sum of the squares of the first `n` odd numbers. The code should start with:
```python
def sum_of_squares_of_n_odds(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_squares_of_n_odds(n: int) -> int:
"""
Calculate the sum of the squares of the first n odd numbers.
Args:
n (int): The number of odd numbers to consider.
Returns:
int: The sum of the squares o... |
evol_instruct_66k | 39,356 | Write a Python function to determine if two dictionaries are congruent, meaning they have the same keys and corresponding values, regardless of the order of the keys. The function should return `True` if the dictionaries are congruent and `False` otherwise. The code should start with:
```python
from typing import Dict
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def are_dictionaries_congruent(dict1: Dict[int, int], dict2: Dict[int, int]) -> bool:
"""
Determines if two dictionaries are congruent, meaning they have the same keys and corresponding values, regardles... |
evol_instruct_66k | 39,359 | Write a Python function to count the occurrences of each character in a given input text and return the result as a dictionary. The dictionary should map each distinct character to the number of times it appears in the text. The function should handle any string input, including those with special characters, spaces, a... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_char_occurrences(text: str) -> Dict[str, int]:
"""
Counts the occurrences of each character in the given input text.
Args:
text (str): The input text to analyze.
Returns:
... |
evol_instruct_66k | 39,381 | Write a Python function to sort a multi-dimensional numerical matrix containing exclusively integers into a decreasing sequence. The function should handle negative integers and zero, and it should work with arbitrarily large matrices. The sorted sequence should consider all values present in the matrix, ignoring the s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_multi_dimensional_matrix(matrix: List[List[int]]) -> List[int]:
"""
Sorts a multi-dimensional numerical matrix containing exclusively integers into a decreasing sequence.
Args:
matr... |
evol_instruct_66k | 39,393 | Write a Python function to convert a time string formatted as "hh:mm:ss" into the equivalent time in seconds. The function should handle input validation to ensure the time string is correctly formatted and within the valid range for hours, minutes, and seconds.
The code should start with:
```python
def time_string_to... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def time_string_to_seconds(time_string: str) -> int:
"""
Converts a time string formatted as "hh:mm:ss" into the equivalent time in seconds.
Args:
time_string (str): The time string to be converted, forma... |
evol_instruct_66k | 39,415 | Write a Python function to implement the Bubble Sort algorithm to sort an array of integer values in ascending order. The function should handle arrays with duplicate integers. The code should start with:
```python
from typing import List
def bubble_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 bubble_sort(arr: List[int]) -> List[int]:
"""
Sorts an array of integers in ascending order using the Bubble Sort algorithm.
Args:
arr (List[int]): The array of integers to be sorted.
... |
evol_instruct_66k | 39,451 | Write a Python function to alternately change the casing of each character in a given string, including special characters using ASCII values. The input will be a mix of English words and numbers in a string. The function should start with:
```python
def alternate_case(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def alternate_case(s: str) -> str:
"""
Alternately changes the casing of each alphabetic character in the given string.
Non-alphabetic characters remain unchanged.
Args:
s (str): The input string containing a mi... |
evol_instruct_66k | 39,471 | Write a Python function to generate a random number within a specified range, ensuring that the function handles edge cases such as negative numbers, zero, and large numbers. The function should also validate the input to ensure that the start value is less than or equal to the end value. If the input is invalid, the f... | 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 between the given start and end values (inclusive).
Args:
start (int): The lower bound of the range (inclusive).... |
evol_instruct_66k | 39,485 | Write a Python function to flatten a given two-dimensional matrix into a one-dimensional list. The matrix is composed of integer elements. The function should handle matrices of varying dimensions and ensure that all elements are included in the resulting list in row-major order.
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 flatten_matrix(matrix: List[List[int]]) -> List[int]:
"""
Flattens a given two-dimensional matrix into a one-dimensional list.
Args:
matrix (List[List[int]]): A two-dimensional matrix co... |
evol_instruct_66k | 39,486 | Write a Python function to calculate the square of a given number, ensuring appropriate variable assignment and error-checking steps. The function should handle both integers and floating-point numbers, and it should return `None` if the input is not a valid number.
The code should start with:
```python
def square_cal... | Here is the Python code to solve the given problem in the markdown block:
```python
def square_calc(num):
"""
Calculate the square of a given number.
Args:
num: The number for which to calculate the square. Can be an integer or a floating-point number.
Returns:
float: The square of the... |
evol_instruct_66k | 39,492 | Write a Python function to generate the first 'n' integers that are divisible by two. The function should return a list of these integers. The code should start with:
```python
from typing import List
def first_n_even_numbers(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def first_n_even_numbers(n: int) -> List[int]:
"""
Generate the first 'n' even integers.
Args:
n (int): The number of even integers to generate.
Returns:
List[int]: A list con... |
evol_instruct_66k | 39,497 | Write a Python function to find the second highest numerical value in a given list of integers, ensuring that duplicates are removed before determining the result. The function should handle lists with or without duplicates and should return `None` if the list has fewer than two unique elements.
The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_second_highest(num_list: List[int]) -> Optional[int]:
"""
Find the second highest numerical value in a given list of integers,
ensuring that duplicates are removed before determini... |
evol_instruct_66k | 39,498 | Write a Python function to generate a random character within a given range of characters. The function should accept two parameters: `start` and `end`, which are characters representing the inclusive range of characters to choose from. The function should return a single random character from this range.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_random_char(start: str, end: str) -> str:
"""
Generates a random character within the given range of characters.
Args:
start (str): The starting character of the range (inclusive).
... |
evol_instruct_66k | 39,500 | Write a Python function to find all unique keys (both own and inherited) in a given dictionary, including those inherited from its nested dictionaries. The function should return a set of all unique keys found in the dictionary and its nested dictionaries.
The code should start with:
```python
from typing import Dict,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Set
def find_all_unique_keys(dictionary: Dict) -> Set[str]:
"""
Find all unique keys in a given dictionary, including those inherited from nested dictionaries.
Args:
dictionary (Dict): The ... |
evol_instruct_66k | 39,502 | Write a Python function to generate all unique combinations of three elements from a given list of integers. The function should be highly efficient in terms of both time and space complexity. The function should not use any in-built Python libraries, functions, or data structures except for lists. Implement your own m... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def generate_triplets(num_list: List[int]) -> List[Tuple[int, int, int]]:
"""
Generate all unique combinations of three elements from a given list of integers.
Args:
num_list (List[in... |
evol_instruct_66k | 39,542 | Write a Python function to compute the element-wise product of two equal-sized lists and return the resulting list. If the input lists are not of equal length, the function should return an error message.
The code should start with:
```python
from typing import List, Union
def element_wise_product(list1: List[int], l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def element_wise_product(list1: List[int], list2: List[int]) -> Union[List[int], str]:
"""
Computes the element-wise product of two equal-sized lists and returns the resulting list.
If the inp... |
evol_instruct_66k | 39,553 | Write a Python function to reverse the order of keys at the second level in a nested dictionary while preserving the original order of keys at the first level. Additionally, return the value whose key was initially last after the second level key order reversal within each first level key.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def reverse_second_level_keys(nested_dict: Dict[str, Dict[str, int]]) -> Tuple[Dict[str, Dict[str, int]], List[int]]:
"""
Reverses the order of keys at the second level in a nested dictionar... |
evol_instruct_66k | 39,554 | Write a Python function to find the maximum value in a given list of integers. The function should efficiently determine the highest value present in the list. The code should start with:
```python
from typing import List
def find_max_value(array: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def find_max_value(array: List[int]) -> int:
"""
Find the maximum value in a given list of integers.
Args:
array (List[int]): The list of integers from which to find the maximum value.
... |
evol_instruct_66k | 39,564 | Write a Python function to determine if one string is a permutation of another. A permutation of a string is another string that contains the same characters, only the order of characters can be different. The function should return `True` if one string is a permutation of the other, and `False` otherwise. The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_permutation(str1: str, str2: str) -> bool:
"""
Determines if one string is a permutation of another.
Args:
str1 (str): The first string to compare.
str2 (str): The second string to compare.
Retur... |
evol_instruct_66k | 39,581 | Write a Python function to generate the Fibonacci sequence up to a specified number `n` where `n` is a positive integer. The function should return a list containing the Fibonacci sequence up to the `n`-th term. If `n` is less than 1, the function should return an empty list.
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 generate_fibonacci(n: int) -> List[int]:
"""
Generate the Fibonacci sequence up to the n-th term.
Args:
n (int): The number of terms in the Fibonacci sequence to generate.
Returns:
... |
evol_instruct_66k | 39,598 | Write a Python function to output positional arguments passed to it and handle improper usage of positional parameters by displaying an appropriate error message. The function should be efficient and capable of handling a large number of parameters. The code should start with:
```python
from typing import List
def pro... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def process_arguments(args: List[str]) -> None:
"""
Process and print positional arguments passed to the function.
If the input is invalid, display an appropriate error message.
Args:
ar... |
evol_instruct_66k | 39,602 | Write a Python function to generate a random floating-point number within a specified range. The function should allow customization of both the lower and upper bounds of the range. The default range should be from -5 to 5.
The code should start with:
```python
import random
def generate_random_float(low: float = -5,... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
def generate_random_float(low: float = -5, high: float = 5) -> float:
"""
Generates a random floating-point number within the specified range.
Args:
low (float, optional): The lower bound of the range... |
evol_instruct_66k | 39,612 | Write a Python function to transform a given matrix of hexadecimal strings to a matrix of decimal integers. The matrix is represented as a list of lists, where each inner list contains hexadecimal strings. The function should convert each hexadecimal string to its corresponding decimal integer.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def hex_matrix_to_dec(matrix: List[List[str]]) -> List[List[int]]:
"""
Converts a matrix of hexadecimal strings to a matrix of decimal integers.
Args:
matrix (List[List[str]]): A list of lis... |
evol_instruct_66k | 39,615 | Write a Python function to search for a target integer in an array of integers using both linear search and binary search algorithms. The function should return the index of the target if found, otherwise return -1. The function should also determine which search algorithm to use based on whether the array is sorted or... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def search_in_array(arr: List[int], target: int) -> int:
"""
Searches for a target integer in an array of integers using either linear search or binary search.
Args:
arr (List[int]): The arr... |
evol_instruct_66k | 39,624 | Write a Python function to generate n-grams from a given text with a specified window size. An n-gram is a contiguous sequence of n items from a given sample of text. The function should handle cases where the window size is greater than the number of words in the text.
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 generate_ngrams(text: str, n: int) -> List[str]:
"""
Generate n-grams from the given text with a specified window size.
Args:
text (str): The input text from which to generate n-grams.
... |
evol_instruct_66k | 39,630 | Write a Python function to sort a given list of alphanumeric strings in ascending order based on their numerical value. If two strings have the same numerical value, they should be sorted alphabetically by their character. The function should be efficient and handle large datasets.
The code should start with:
```pytho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_alphanumeric_strings(arr: List[str]) -> List[str]:
"""
Sorts a list of alphanumeric strings in ascending order based on their numerical value.
If two strings have the same numerical value, t... |
evol_instruct_66k | 39,651 | Write a Python function to invert the order of elements in a given list without using any predefined or built-in methods for reversing the list. The function should swap elements from the start and end of the list, moving towards the center until the entire list is reversed.
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 reverse_array_in_place(arr: List[int]) -> List[int]:
"""
Reverses the order of elements in a given list without using any built-in methods.
Args:
arr (List[int]): The list of integers to... |
evol_instruct_66k | 39,669 | Write a Python function to reorder a given list of integers in descending order. The function should take a list of integers as input and return a new list with the integers sorted in descending order. The original list should not be modified.
The code should start with:
```python
from typing import List
def sort_des... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_descending(numbers: List[int]) -> List[int]:
"""
Sorts a given list of integers in descending order and returns the sorted list.
Args:
numbers (List[int]): The list of integers to b... |
evol_instruct_66k | 39,703 | Write a Python function to reverse each word in a given sentence while preserving the order of the words in the sentence. The function should handle sentences with varying lengths and different types of characters, including spaces and punctuation. The code should start with:
```python
def reverse_each_word_in_sentence... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_each_word_in_sentence(sentence: str) -> str:
"""
Reverses each word in the given sentence while preserving the order of the words.
Args:
sentence (str): The input sentence whose words are to be reversed.... |
evol_instruct_66k | 39,709 | Write a Python function to generate the Fibonacci sequence up to the nth term. The function should return a list containing the Fibonacci sequence. The code should start with:
```python
from typing import List
def fibonacci_sequence(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def fibonacci_sequence(n: int) -> List[int]:
"""
Generate the Fibonacci sequence up to the nth term.
Args:
n (int): The number of terms in the Fibonacci sequence to generate.
Returns:
... |
evol_instruct_66k | 39,713 | Write a Python function to create a dictionary from a given list where the keys are the distinct items from the list, and the corresponding values are the counts of their occurrences in the list. The function should be efficient and avoid redundant calculations.
The code should start with:
```python
from typing import... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_frequency_dict(lst: List[str]) -> Dict[str, int]:
"""
Creates a dictionary from a list where the keys are the distinct items from the list,
and the corresponding values are the count... |
evol_instruct_66k | 39,720 | Write a Python function to calculate the cumulative total of all elements within a given list of integers. The function should return a new list where each element at index `i` is the sum of all elements from the original list up to index `i`.
The code should start with:
```python
from typing import List
def cumulati... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cumulative_sum(lst: List[int]) -> List[int]:
"""
Calculate the cumulative sum of elements in a list.
Args:
lst (List[int]): The list of integers for which to calculate the cumulative sum... |
evol_instruct_66k | 39,725 | Write a Python function to concatenate two strings and then replace a specific substring in the concatenated result with another string. The function should take three parameters: the first string, the second string, and the substring to be replaced. The function should return the modified concatenated string.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
def concatenate_and_replace(first_str: str, second_str: str, to_replace: str, replacement: str) -> str:
"""
Concatenates two strings and replaces a specified substring in the concatenated result with another string.
Args:
... |
evol_instruct_66k | 39,726 | Write a Python function to convert a list of integers into a dictionary where the keys are the indices of the elements in the list and the values are the elements themselves. The function should then return the dictionary. The code should start with:
```python
from typing import List, Dict
def list_to_dict(items: List... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Dict
def list_to_dict(items: List[int]) -> Dict[int, int]:
"""
Converts a list of integers into a dictionary where the keys are the indices of the elements in the list and the values are the elements ... |
evol_instruct_66k | 39,754 | Write a Python function to perform a ternary search on a sorted array to find the index of a given key. The ternary search divides the array into three parts at each step and narrows down the search space accordingly. If the key is found, return its index; otherwise, return -1.
The code should start with:
```python
fr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def ternary_search(arr: List[int], key: int) -> int:
"""
Perform a ternary search on a sorted array to find the index of a given key.
Args:
arr (List[int]): A sorted list of integers.
... |
evol_instruct_66k | 39,763 | Write a Python function to convert a given string to its hexadecimal representation and another function to convert a given hexadecimal string back to its original string. The functions should handle the conversion between UTF-8 encoded strings and their corresponding hexadecimal representations.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
def string_to_hex(s: str) -> str:
"""
Convert a given string to its hexadecimal representation.
Args:
s (str): The input string to be converted.
Returns:
str: The hexadecimal representation of the input... |
evol_instruct_66k | 39,770 | Write a Python function to construct a comprehensive internet URL using the HTTPS protocol, incorporating the given subdomain, domain, and path segment. Ensure these constituent parts are correctly integrated into the resultant World Wide Web address. The function should handle the input strings and format them appropr... | Here is the Python code to solve the given problem in the markdown block:
```python
def construct_url(subdomain: str, domain: str, path: str) -> str:
"""
Constructs a comprehensive internet URL using the HTTPS protocol, incorporating the given subdomain, domain, and path segment.
Args:
subdomain (s... |
evol_instruct_66k | 39,783 | Write a Python function to filter out odd numbers from a given list of integers. The function should return a new list containing only the odd numbers from the input list. The code should start with:
```python
from typing import List
def filter_odd_numbers(input_array: 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_odd_numbers(input_array: List[int]) -> List[int]:
"""
Filters out odd numbers from the given list of integers.
Args:
input_array (List[int]): The list of integers from which to fi... |
evol_instruct_66k | 39,784 | Write a Python function to find the maximum sum of a contiguous subarray within a given array of integers. The function should be optimized for performance, avoiding nested loops and redundant calculations. The code should start with:
```python
from typing import List
def max_subarray_sum(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_subarray_sum(arr: List[int]) -> int:
"""
Find the maximum sum of a contiguous subarray within the given array.
Args:
arr (List[int]): The array of integers.
Returns:
int... |
evol_instruct_66k | 39,788 | Write a Python function to sort the strings in a 2D array of mixed data types (strings and integers) alphabetically without changing the positions of the integers. Strings should maintain their original index positions in the returned array, and if there are multiple strings at the same index position, they should be o... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def sort_strings_in_arrays(array: List[List[Union[str, int]]]) -> List[List[Union[str, int]]]:
"""
Sorts the strings in a 2D array of mixed data types (strings and integers) alphabetically without... |
evol_instruct_66k | 39,797 | Write a Python function to filter a list and return a new list containing only the elements that occur an odd number of times in the input list. The function should be efficient and handle any list of integers.
The code should start with:
```python
from typing import List
def filter_odd_occurrences(lst: List[int]) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_odd_occurrences(lst: List[int]) -> List[int]:
"""
Filters the input list and returns a new list containing only the elements that occur an odd number of times.
Args:
lst (List[int... |
evol_instruct_66k | 39,813 | Write a Python function to sort only the strings in a given list of mixed data types (integers and strings) in ascending alphabetical order while leaving the integers untouched. The function should handle lists with varying numbers of integers and strings. 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, Union
def sort_mixed_list(mixed_list: List[Union[int, str]]) -> List[Union[int, str]]:
"""
Sorts only the strings in a given list of mixed data types (integers and strings) in ascending alphabetical ord... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.