source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
evol_instruct_66k | 35,413 | Write a Python function to simulate two rounds of shuffling on an array. In the first round, divide the array into two equal halves (or nearly equal if the array's length is odd), then interleave elements from each half back into the array such that the first element is from the first half, the second element is from t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def shuffle_array(arr: List[int]) -> List[int]:
"""
Simulates two rounds of shuffling on an array.
In the first round, the array is divided into two equal halves (or nearly equal if th... |
evol_instruct_66k | 35,414 | Write a Python function to move the element at a specified index in a list to the end of the list. If the element is already at the end, move it to the beginning. The function should operate in O(1) time complexity. The code should start with:
```python
from typing import List
def move_element_to_end(lst: List[int], i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def move_element_to_end(lst: List[int], index: int) -> List[int]:
"""
Move the element at the specified index to the end of the list. If the element is already at the end, move it to the beginning.
... |
evol_instruct_66k | 35,424 | Write a Python function to sort three unique objects based on a multi-step reasoning process. The objects are defined by their distinctive characteristics:
- Object 1: circular, ruby-red, with a 5cm diameter
- Object 2: four-sided, emerald green, sized at 10cm
- Object 3: triangular, bright scarlet, measuring 8cm in le... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Optional, Dict
def identify_object(obj: Dict[str, str]) -> Optional[int]:
"""
Identify an object based on its characteristics and return its identifier.
Args:
obj (Dict[str, str]): A dictionary r... |
evol_instruct_66k | 35,428 | Write a Python function to remove all empty lists from a given list of lists. The function should return the modified list without any empty lists. The code should start with:
```python
from typing import List
def remove_empty_lists(nested_list: List[List[any]]) -> List[List[any]]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_empty_lists(nested_list: List[List[any]]) -> List[List[any]]:
"""
Removes all empty lists from a given list of lists.
Args:
nested_list (List[List[any]]): The list of lists from w... |
evol_instruct_66k | 35,430 | Write a Python function to generate the first `n` numbers in the Fibonacci sequence using an array data structure. The function should return the array containing the Fibonacci sequence.
The code should start with:
```python
from typing import List
def generate_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 generate_fibonacci_sequence(n: int) -> List[int]:
"""
Generate the first n numbers in the Fibonacci sequence.
Args:
n (int): The number of Fibonacci numbers to generate.
Returns:
... |
evol_instruct_66k | 35,436 | Write a Python function to count the total number of integers and the number of distinct integers in a given 2D array. The 2D array may contain lists of different lengths, negative integers, and duplicate integers. The function should optimize for a time complexity of at most O(n), where n is the total number of intege... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def count_integers(arr: List[List[int]]) -> Tuple[int, int]:
"""
Counts the total number of integers and the number of distinct integers in a given 2D array.
Args:
arr (List[List[int]... |
evol_instruct_66k | 35,441 | Write a Python function to calculate the absolute numerical disparity between two given values. The function should take two integers as input and return the absolute difference between them. The code should start with:
```python
def calculate_disparity(value1: int, value2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_disparity(value1: int, value2: int) -> int:
"""
Calculate the absolute numerical disparity between two given values.
Args:
value1 (int): The first value.
value2 (int): The second value.
Re... |
evol_instruct_66k | 35,467 | Write a Python function to remove duplicate elements from a given list, sort the list in ascending order, find the 2nd largest element, and calculate the sum of the entire list after duplicate removal and sorting. The function should return a tuple containing the sorted list, the 2nd largest element, and the sum of the... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def process_list(arr: List[int]) -> Tuple[List[int], int, int]:
"""
Processes the given list by removing duplicates, sorting it, finding the 2nd largest element,
and calculating the sum of the... |
evol_instruct_66k | 35,477 | Write a Python function to determine the academic letter grade of an undergraduate scholar based on their arithmetic grade value using a ternary operator. The function should accept an integer representing the arithmetic grade value and return a string representing the corresponding letter grade. The grading scale is a... | Here is the Python code to solve the given problem in the markdown block:
```python
def determine_letter_grade(arithmetic_grade_value: int) -> str:
"""
Determine the academic letter grade of an undergraduate scholar based on their arithmetic grade value.
Args:
arithmetic_grade_value (int): The arit... |
evol_instruct_66k | 35,496 | Write a Python function to create a dictionary from two given lists, where the first list contains the keys and the second list contains the corresponding values. If the lists are of different lengths, the function should handle this by only creating key-value pairs for the elements that have corresponding pairs in bot... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_dict_from_lists(keys: List[str], values: List[int]) -> Dict[str, int]:
"""
Creates a dictionary from two given lists, where the first list contains the keys and the second list contains ... |
evol_instruct_66k | 35,500 | Write a Python function to transform a given tuple of strings into a dictionary where each key is a unique string from the tuple and the corresponding value is the frequency of that string in the tuple. The function should be efficient and handle any size of input tuple.
The code should start with:
```python
from typi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Dict
def tuple_to_frequency_dict(input_tuple: Tuple[str]) -> Dict[str, int]:
"""
Transforms a tuple of strings into a dictionary where each key is a unique string from the tuple
and the correspondi... |
evol_instruct_66k | 35,504 | Write a Python function to calculate and return a list of cubes of sequential integers, starting from a given integer `start` and ending at a given integer `end` (inclusive). The function should handle cases where `start` is greater than `end` by returning an empty list. 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 calculate_cubes(start: int, end: int) -> List[int]:
"""
Calculate and return a list of cubes of sequential integers from `start` to `end` (inclusive).
Args:
start (int): The starting int... |
evol_instruct_66k | 35,507 | Write a Python function to determine if two provided lists contain the same elements, regardless of their order. The function should return `True` if the lists are identical in content, and `False` otherwise. The code should start with:
```python
from typing import List
def are_lists_identical(list1: List[int], list2:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def are_lists_identical(list1: List[int], list2: List[int]) -> bool:
"""
Determines if two lists contain the same elements, regardless of their order.
Args:
list1 (List[int]): The first list... |
evol_instruct_66k | 35,509 | Write a Python function to perform a comparative analysis of two given sets of numbers and determine if the first set is less than the second set based on a specified criterion. The criterion can be one of the following:
1. The sum of the elements in the first set is less than the sum of the elements in the second set.... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Literal
def is_set1_less_than_set2(set1: List[int], set2: List[int], criterion: Literal['sum', 'min', 'elementwise']) -> bool:
"""
Compare two sets of numbers based on a specified criterion and determin... |
evol_instruct_66k | 35,515 | Write a Python function to calculate the sum of the first `n` natural numbers. The function should handle edge cases such as `n` being zero or negative. The code should start with:
```python
def sum_of_first_n_numbers(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_first_n_numbers(n: int) -> int:
"""
Calculate the sum of the first n natural numbers.
Args:
n (int): The number of natural numbers to sum.
Returns:
int: The sum of the first n natural numbers... |
evol_instruct_66k | 35,517 | Write a Python function to determine if an array contains any recurring elements. The function should return a list of all recurring elements found in the array. If no recurring elements are found, the function should return an empty list.
The code should start with:
```python
from typing import List
def find_recurri... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_recurring_elements(arr: List[int]) -> List[int]:
"""
Finds all recurring elements in the given array.
Args:
arr (List[int]): The array to be analyzed for recurring elements.
Re... |
evol_instruct_66k | 35,524 | Write a Python function to increment each alphabetic character in a given sentence by one position in the alphabet. Non-alphabetic characters should remain unchanged. The function should handle both uppercase and lowercase letters, wrapping around from 'z' to 'a' and from 'Z' to 'A'.
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
def increment_character(s: str) -> str:
"""
Increments each alphabetic character in the given string by one position in the alphabet.
Non-alphabetic characters remain unchanged.
Args:
s (str): The input string t... |
evol_instruct_66k | 35,541 | Write a Python function to find the median of two sorted sequences efficiently. The function should not merge the sequences directly but should use a more optimal approach to determine the median.
The code should start with:
```python
from typing import List
def find_median_of_two_sorted_sequences(sequence1: List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_median_of_two_sorted_sequences(sequence1: List[int], sequence2: List[int]) -> float:
"""
Finds the median of two sorted sequences efficiently.
Args:
sequence1 (List[int]): The first... |
evol_instruct_66k | 35,545 | Write a Python function to reverse the words in a given string. The function should take a string as input and return a new string with the words in reverse order. The words in the input string are separated by spaces. The function should handle multiple spaces between words and leading/trailing spaces.
The code shoul... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_words(s: str) -> str:
"""
Reverses the words in a given string.
Args:
s (str): The input string containing words separated by spaces.
Returns:
str: A new string with the words in reverse ord... |
evol_instruct_66k | 35,568 | Write a Python function to perform division of two integers without using the division operator '/', the math library, or any loops. The function should handle scenarios where the divisor is zero by returning `None`. The function should also handle negative numbers and return the correct sign for the quotient.
The cod... | Here is the Python code to solve the given problem in the markdown block:
```python
def divide(dividend: int, divisor: int) -> int:
"""
Perform division of two integers without using the division operator '/',
without using any loops, and without using the math library. If the
divisor is zero, then ret... |
evol_instruct_66k | 35,583 | Write a Python function to get the current local time with high accuracy. The function should return the current local time as a string formatted in the ISO 8601 standard. The code should start with:
```python
from datetime import datetime
def get_current_local_time() -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from datetime import datetime
def get_current_local_time() -> str:
"""
Get the current local time with high accuracy and return it in ISO 8601 format.
Returns:
str: The current local time formatted as an ISO 8601... |
evol_instruct_66k | 35,593 | Write a Python function to generate a list of all prime numbers up to a given integer `n` in ascending order. The function should efficiently determine whether a number is prime by checking for divisors up to the square root of the number.
The code should start with:
```python
from typing import List
def generate_pri... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_primes(n: int) -> List[int]:
"""
Generate a list of all prime numbers up to a given integer `n`.
Args:
n (int): The upper limit for generating prime numbers.
Returns:
... |
evol_instruct_66k | 35,600 | Write a Python function to perform 2D interpolation search on a matrix. The matrix is a list of lists, where each sublist represents a row in the matrix. The matrix is sorted both row-wise and column-wise. Given a target value `y`, the function should return the indices of `y` in the matrix. If `y` is not found, the fu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def interpolation_search_matrix(mtx: List[List[int]], y: int) -> Tuple[int, int]:
"""
Perform a 2D interpolation search on a sorted matrix to find the indices of a target value.
Args:
... |
evol_instruct_66k | 35,605 | Write a Python function to calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid, where you can only move right or down. The function should start with:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def unique_paths(m: int, n: int) -> int:
"""
Calculate the number of unique paths from the top-left corner to the bottom-right corner of an m x n grid.
Args:
m (int): The number of row... |
evol_instruct_66k | 35,607 | Write a Python function to determine if a given 2-dimensional array is a magic square. A magic square is a square matrix where the sums of every row, every column, and both diagonals are equal. The function should take a 2D list as input and return a boolean indicating whether the array is a magic square.
The code sho... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_magic_square(arr: List[List[int]]) -> bool:
"""
Determines if a given 2-dimensional array is a magic square.
Args:
arr (List[List[int]]): A 2D list representing the matrix to be check... |
evol_instruct_66k | 35,617 | Write a Python function to generate two separate lists: one containing consecutive natural numbers starting from 1 up to a provided number `n`, and the other containing only the even numbers within that range. The function should return both lists. The code should start with:
```python
from typing import Tuple, List
d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, List
def generate_natural_and_even_numbers(n: int) -> Tuple[List[int], List[int]]:
"""
Generates two lists: one containing consecutive natural numbers from 1 to n,
and the other containing only the... |
evol_instruct_66k | 35,619 | Write a Python function to find and return the common positive factors of two given integers, `Y` and `Z`. The function should efficiently determine the common factors by iterating only up to the smaller of the two numbers.
The code should start with:
```python
from typing import List
def find_common_factors(Y: int, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_common_factors(Y: int, Z: int) -> List[int]:
"""
Find and return the common positive factors of two given integers, Y and Z.
Args:
Y (int): The first integer.
Z (int): The s... |
evol_instruct_66k | 35,625 | Write a Python function to determine if a given string is a valid JSON object. The function should return `True` if the string is a valid JSON object, and `False` otherwise. The function should handle various edge cases, such as empty strings, strings that are not JSON objects, and JSON objects with different data type... | Here is the Python code to solve the given problem in the markdown block:
```python
import json
def is_valid_json(json_string: str) -> bool:
"""
Determines if the given string is a valid JSON object.
Args:
json_string (str): The string to be checked for JSON validity.
Returns:
bool: T... |
evol_instruct_66k | 35,635 | Write a Python function to find the smallest positive integer `b` such that the product of its digits equals a given positive integer `a`. If no such integer exists or if the result exceeds the capacity of a 32-bit signed integer, return 0.
The code should start with:
```python
def smallest_factorization(a: int) -> in... | Here is the Python code to solve the given problem in the markdown block:
```python
def smallest_factorization(a: int) -> int:
"""
Find the smallest positive integer `b` such that the product of its digits equals the given positive integer `a`.
If no such integer exists or if the result exceeds the capacity... |
evol_instruct_66k | 35,636 | Write a Python function to compute the greatest common divisor (GCD) of two given integers using the Euclidean algorithm. The Euclidean algorithm is an efficient method for computing the GCD by repeatedly applying the principle that the GCD of two numbers also divides their difference.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
def compute_gcd_euclidean(num1: int, num2: int) -> int:
"""
Compute the greatest common divisor (GCD) of two integers using the Euclidean algorithm.
Args:
num1 (int): The first integer.
num2 (int): The secon... |
evol_instruct_66k | 35,647 | Write a Python function to save a given NumPy array to a binary file with a `.npy` extension and load it back into a NumPy array. The function should ensure efficient space consumption and handle the file operations correctly.
The code should start with:
```python
import numpy as np
def save_and_load_array(array: np.... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def save_and_load_array(array: np.ndarray, filename: str) -> np.ndarray:
"""
Saves a given NumPy array to a binary file with a .npy extension and loads it back.
Args:
array (np.ndarray): The NumP... |
evol_instruct_66k | 35,649 | Write a Python function to find the k-th largest number from a given array of non-repeating integers without using any inbuilt sorting function. The function should be efficient and should not modify the original array.
The code should start with:
```python
from typing import List
def kth_largest(arr: List[int], k: i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def kth_largest(arr: List[int], k: int) -> int:
"""
Find the k-th largest number from a given array of non-repeating integers without using any inbuilt sorting function.
Args:
arr (List[int]... |
evol_instruct_66k | 35,650 | Write a Python function to integrate underscores in the gaps between words that terminate with punctuation symbols within a provided textual string. The function should be capable of handling multiple punctuation marks and varying sentence structures. The code should start with:
```python
import re
def integrate_under... | Here is the Python code to solve the given problem in the markdown block:
```python
import re
def integrate_underscores(text: str) -> str:
"""
Integrates underscores in the gaps between words that terminate with punctuation symbols within a provided textual string.
Args:
text (str): The input text... |
evol_instruct_66k | 35,655 | Write a Python function to create a two-dimensional matrix of size `m x n` where every element 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_matrix(m: int, n: int, value: int) -> List[List[int]]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def create_matrix(m: int, n: int, value: int) -> List[List[int]]:
"""
Create a two-dimensional matrix of size m x n where every element is initialized to the specified value.
Args:
m (int): ... |
evol_instruct_66k | 35,664 | Write a Python function to create a NumPy array that contains a specified number of negative sevens and a specified number of twenties. The function should take two integer parameters: `num_neg_sevens` and `num_twenties`, which represent the number of negative sevens and twenties to include in the array, respectively. ... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def create_array(num_neg_sevens: int, num_twenties: int) -> np.ndarray:
"""
Creates a NumPy array containing a specified number of negative sevens and twenties.
Args:
num_neg_sevens (int): The nu... |
evol_instruct_66k | 35,674 | Write a Python function to generate a list of `n` random numbers within a specified range `[min_value, max_value]`. The function should ensure that the generated numbers are unique and sorted in ascending order. The code should start with:
```python
from typing import List
import random
def generate_unique_random_numb... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_unique_random_numbers(n: int, min_value: int, max_value: int) -> List[int]:
"""
Generates a list of n unique random numbers within the specified range [min_value, max_value] an... |
evol_instruct_66k | 35,676 | Write a Python function to remove all even numbers from a given list of integers. The function should return a new list containing only the odd numbers from the original list. The code should start with:
```python
from typing import List
def remove_even_numbers(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 remove_even_numbers(arr: List[int]) -> List[int]:
"""
Removes all even numbers from the given list of integers and returns a new list containing only the odd numbers.
Args:
arr (List[int... |
evol_instruct_66k | 35,686 | Write a Python function that iterates through a range of numbers and prints "Hello, world!" on the 5th iteration. The function should then stop execution after printing "Hello, world!". The function should accept a single integer parameter `n` which defines the upper limit of the range (exclusive). The function should ... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_hello_world_on_fifth_iteration(n: int):
"""
Iterates through a range of numbers from 1 to n (exclusive) and prints "Hello, world!" on the 5th iteration.
The function then stops execution after printing "Hello, worl... |
evol_instruct_66k | 35,702 | Write a Python function to loop through a given list and return a string where each item from the list is printed on a new line. The function should handle lists of any length and any type of elements. The code should start with:
```python
from typing import List, Any
def list_to_string(my_list: List[Any]) -> str:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def list_to_string(my_list: List[Any]) -> str:
"""
Converts a list of any type of elements into a string where each item is on a new line.
Args:
my_list (List[Any]): The list of element... |
evol_instruct_66k | 35,706 | Write a Python function to verify the presence of a predetermined character sequence (substring) within a given text string. The function should return `True` if the substring is found in the text string, and `False` otherwise. The function should be case-sensitive.
The code should start with:
```python
def check_subs... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_substring(text: str, substring: str) -> bool:
"""
Verifies the presence of a predetermined character sequence (substring) within a given text string.
Args:
text (str): The main text string in which to sear... |
evol_instruct_66k | 35,721 | Write a Python function to calculate the aggregate yield resulting from the summation operation on the integer components within a given list. The function should handle lists of integers and return the sum of all elements in the list.
The code should start with:
```python
from typing import List
def calculate_aggreg... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_aggregate_yield(my_list: List[int]) -> int:
"""
Calculate the aggregate yield by summing all integer components in the given list.
Args:
my_list (List[int]): A list of integers... |
evol_instruct_66k | 35,722 | Write a Python function to iterate through each key-value pair in a given dictionary and return a list of tuples where each tuple contains a key and its corresponding value. The function should handle dictionaries of any size and structure.
The code should start with:
```python
from typing import Dict, List, Tuple
de... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def iterate_dictionary(dictionary: Dict[str, int]) -> List[Tuple[str, int]]:
"""
Iterates through each key-value pair in the given dictionary and returns a list of tuples.
Args:
... |
evol_instruct_66k | 35,736 | Write a Python function to convert a given string to uppercase. The function should handle strings of varying lengths and characters, including special characters and numbers. The code should start with:
```python
def convert_to_uppercase(input_string: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def convert_to_uppercase(input_string: str) -> str:
"""
Converts the given string to uppercase.
Args:
input_string (str): The string to be converted to uppercase.
Returns:
str: The uppercase version of ... |
evol_instruct_66k | 35,739 | Write a Python function to replace `NULL` values in the second column of a given SQL table with the corresponding values from the first column, but only for rows that meet a specific condition based on another related table. The function should execute all changes as a transaction and handle potential errors by rolling... | Here is the Python code to solve the given problem in the markdown block:
```python
import sqlite3
def update_null_values(db_path: str, table_b: str, table_a: str, column_x: str, column_y: str, column_z: str, condition_value: str) -> None:
"""
Updates NULL values in the second column of a given SQL table with ... |
evol_instruct_66k | 35,745 | Write a Python function to compute the value of a mathematical function \( f(x, y) = x^3 + 2y^2 \) given two integer inputs \( x \) and \( y \). The function should return the computed value.
The code should start with:
```python
def compute_function_value(x: int, y: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def compute_function_value(x: int, y: int) -> int:
"""
Computes the value of the mathematical function f(x, y) = x^3 + 2y^2.
Args:
x (int): The first integer input.
y (int): The second integer input.
Re... |
evol_instruct_66k | 35,776 | Write a Python function to add elements to the beginning of a list. The function should take a list and a variable number of elements to be added as arguments. The function should return the updated list with the new elements at the beginning.
The code should start with:
```python
from typing import List, Any
def add... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def add_to_beginning(lst: List[Any], *elements: Any) -> List[Any]:
"""
Adds the given elements to the beginning of the list and returns the updated list.
Args:
lst (List[Any]): The orig... |
evol_instruct_66k | 35,778 | Write a Python function to extract the value located at the 7th position in a given numpy array, considering the zero-based index nature of Python data structures. The function should handle the input array and return the value at the specified position.
The code should start with:
```python
import numpy as np
def ex... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def extract_value_at_position(arr: np.ndarray, position: int) -> int:
"""
Extracts the value located at the specified position in a given numpy array.
Args:
arr (np.ndarray): The numpy array from... |
evol_instruct_66k | 35,780 | Write a Python function to find all prime numbers within a given range that are also square-free, and determine if the sum of these prime, square-free numbers is even or odd. The function should efficiently verify the correctness of the results.
The code should start with:
```python
from typing import List, Tuple
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
import math
def find_prime_square_free_numbers(start: int, end: int) -> Tuple[List[int], str]:
"""
Find all prime numbers within a given range that are also square-free, and determine if their sum... |
evol_instruct_66k | 35,781 | Write a Python function to calculate the minimum number of operations required to return to the main folder after executing a series of change folder operations. The operations are defined as follows:
- `"../"`: Move to the parent folder of the current folder (if already in the main folder, stay in the same folder).
- ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def min_operations_to_main_folder(logs: List[str]) -> int:
"""
Calculate the minimum number of operations required to return to the main folder
after executing a series of change folder operations.
... |
evol_instruct_66k | 35,782 | Write a Python function to calculate the frequency of two specific characters in a given string, including their separate and cumulative frequencies. The function should return a dictionary containing the counts of each character and their combined total.
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 character_frequency(string: str, character_1: str, character_2: str) -> Dict[str, int]:
"""
Calculate the frequency of two specific characters in a given string, including their separate and cumulati... |
evol_instruct_66k | 35,784 | Write a Python function to insert an element into the penultimate position of a given list. If the list has fewer than two elements, return an error message. The function should handle lists of any length and any type of elements.
The code should start with:
```python
from typing import List, Any
def insert_penultima... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def insert_penultimate(arr: List[Any], elem: Any) -> List[Any] or str:
"""
Inserts an element into the penultimate position of a given list.
Args:
arr (List[Any]): The list into which t... |
evol_instruct_66k | 35,809 | Write a Python function to swap the case of each character in a given string. The function should convert all uppercase letters to lowercase and all lowercase letters to uppercase. Non-alphabetic characters should remain unchanged.
The code should start with:
```python
def swap_case(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def swap_case(s: str) -> str:
"""
Swaps the case of each character in the given string.
Args:
s (str): The input string to be processed.
Returns:
str: A new string with all uppercase letters changed to ... |
evol_instruct_66k | 35,820 | Write a Python function to generate all distinct permutations of a given list of words. The function should return a list of tuples, where each tuple represents a unique permutation of the input list. The code should start with:
```python
from typing import List, Tuple
def generate_permutations(words: List[str]) -> Li... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List, Tuple
from itertools import permutations
def generate_permutations(words: List[str]) -> List[Tuple[str]]:
"""
Generate all distinct permutations of a given list of words.
Args:
words (Lis... |
evol_instruct_66k | 35,824 | Write a Python function to compute the cumulative multiplication of all numerical values in a given list. The function should use a while loop to iterate through the list and accumulate the product of the elements. The code should start with:
```python
from typing import List
def cumulative_multiplication(num_list: Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cumulative_multiplication(num_list: List[int]) -> int:
"""
Compute the cumulative multiplication of all numerical values in a given list.
Args:
num_list (List[int]): The list of integers... |
evol_instruct_66k | 35,828 | Write a Python function to find and return the three smallest elements from a given list of integers. The function should be efficient and handle cases where the list has fewer than three elements. The code should start with:
```python
from typing import List
def find_three_smallest(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 find_three_smallest(arr: List[int]) -> List[int]:
"""
Finds and returns the three smallest elements from a given list of integers.
Args:
arr (List[int]): The list of integers from which ... |
evol_instruct_66k | 35,838 | Write a Python function to select `n` distinct elements from a given list `arr` in a systematic and logical manner. The function should ensure that the elements are selected in the order they appear in the list. If the number of elements requested (`n`) exceeds the length of the list, the function should return a messa... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def select_distinct_elements(arr: List[int], n: int) -> Union[List[int], str]:
"""
Selects the first `n` distinct elements from the given list `arr` in the order they appear.
Args:
ar... |
evol_instruct_66k | 35,841 | Write a Python function to find the second maximum value from a given array of integers, considering scenarios where the array may contain negative integers and repeated numbers. The function should handle arrays of any length, not just 9 elements. The code should start with:
```python
from typing import List
def find... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_second_max(arr: List[int]) -> int:
"""
Find the second maximum value from a given array of integers.
Args:
arr (List[int]): The array of integers from which to find the second maxim... |
evol_instruct_66k | 35,871 | Write a Python function to concatenate a list of integers in reverse order as a single string. The function should take a list of integers as input and return a string that is the concatenation of the integers in reverse order.
The code should start with:
```python
from typing import List
def reverse_concatenate_inte... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_concatenate_integers(int_list: List[int]) -> str:
"""
Concatenates a list of integers in reverse order as a single string.
Args:
int_list (List[int]): A list of integers to be co... |
evol_instruct_66k | 35,885 | Write a Python function to sort an array of integers using two custom sorting algorithms: one with time complexity O(n^2), such as bubble sort or insertion sort, and another one with time complexity O(n log n), such as quicksort or merge sort. The function should return the sorted array. Additionally, analyze and comme... | 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], algorithm: str = 'bubble') -> List[int]:
"""
Sorts an array of integers using a custom sorting algorithm.
Args:
arr (List[int]): The array of integers to be s... |
evol_instruct_66k | 35,888 | Write a Python function to perform a bitwise operation between two given integers and return the result. The function should accept two integers as input and return the result of the bitwise AND operation between them. The function should also ensure that the input values are integers and handle cases where the input i... | Here is the Python code to solve the given problem in the markdown block:
```python
def bitwise_and(a: int, b: int) -> int:
"""
Perform a bitwise AND operation between two integers and return the result.
Args:
a (int): The first integer.
b (int): The second integer.
Returns:
in... |
evol_instruct_66k | 35,897 | Write a Python function to determine if two 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 be efficient and handle case insensitivity and spaces.
The code shou... | Here is the Python code to solve the given problem in the markdown block:
```python
from collections import Counter
def are_anagrams(s1: str, s2: str) -> bool:
"""
Determine if two strings are anagrams of each other.
Args:
s1 (str): The first string to compare.
s2 (str): The second string ... |
evol_instruct_66k | 35,900 | Write a Python function to multiply each element of a given list of integers by a specified scalar factor. The function should return a new list containing the results of these multiplications. The code should start with:
```python
from typing import List
def multiply_elements(arr: List[int], factor: int) -> List[int]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiply_elements(arr: List[int], factor: int) -> List[int]:
"""
Multiplies each element of the given list by the specified factor and returns a new list with the results.
Args:
arr (Lis... |
evol_instruct_66k | 35,935 | Write a Python function to sort a given list of complex numbers in ascending order based on their magnitudes. The function should take a list of complex numbers as input and return the sorted list. The code should start with:
```python
from typing import List
def sort_complex_numbers_by_magnitude(complex_numbers: List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_complex_numbers_by_magnitude(complex_numbers: List[complex]) -> List[complex]:
"""
Sorts a list of complex numbers in ascending order based on their magnitudes.
Args:
complex_number... |
evol_instruct_66k | 35,951 | Write a Python function to calculate the product of the digits of each number in a given list of integers. The function should correctly handle the calculation and return the total product of all digits in the list. The code should start with:
```python
from typing import List
def product_of_digits(numbers: List[int])... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def product_of_digits(numbers: List[int]) -> int:
"""
Calculate the product of the digits of each number in the given list of integers.
Args:
numbers (List[int]): A list of integers whose di... |
evol_instruct_66k | 35,958 | Write a Python function to calculate the total number of vowels (both lowercase and uppercase) in a given input string. The function should be case-insensitive and should count all occurrences of the vowels 'a', 'e', 'i', 'o', 'u' in the input string.
The code should start with:
```python
def count_vowels(input_string... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_vowels(input_string: str) -> int:
"""
Calculate the total number of vowels (both lowercase and uppercase) in the given input string.
Args:
input_string (str): The input string in which to count the vowels.... |
evol_instruct_66k | 35,962 | Write a Python function to print the elements of a given list in reverse order using a while loop. The function should take a list of strings as input and print each element on a new line in reverse order.
The code should start with:
```python
from typing import List
def print_reverse_order(fruits: List[str]) -> None... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_reverse_order(fruits: List[str]) -> None:
"""
Prints the elements of the given list in reverse order.
Args:
fruits (List[str]): A list of strings to be printed in reverse order.
... |
evol_instruct_66k | 35,988 | Write a Python function to update a dictionary `subjectData` with a new key-value pair for specific subjects from a predefined list `allSubjects`. The function should avoid unnecessary dictionary comprehensions and ensure that the update operation is performed efficiently.
The code should start with:
```python
from ty... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def update_subject_data(subjectData: Dict[str, Dict], allSubjects: List[str]) -> Dict[str, Dict]:
"""
Updates the 'subjectData' dictionary with a new key-value pair for each subject in 'allSubjects... |
evol_instruct_66k | 36,007 | Write a Python function to sort a list of movie titles and their release years in descending order by release year, while handling potential data inconsistencies. The function should:
1. Ensure the input is a list of tuples, where each tuple contains a movie title (string) and a release year (integer or string).
2. Con... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Union
from datetime import datetime
def sort_movies(movies: List[Tuple[str, Union[int, str]]]) -> Tuple[List[Tuple[str, int]], List[Tuple[str, Union[int, str]]], List[Tuple[str, Union[int, str]]]]:
"... |
evol_instruct_66k | 36,019 | Write a Python function to find the date and time of a specific course from a given JSON object representing a multi-level nested university schedule. The function should handle cases where the course does not exist in the schedule and should return all time slots and dates if the course has multiple sessions in a week... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Union
def find_course_time(schedule: Dict, course: str) -> Union[str, List[Dict[str, str]]]:
"""
Find the date and time of a specific course from a given university schedule.
Args:
sc... |
evol_instruct_66k | 36,029 | Write a Python function that takes a tuple of homograph strings as input and returns a dictionary where the keys are the homograph strings and the values are the counts of characters in each respective homograph string. The function should handle any tuple of strings, not just the provided example.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
def count_characters(words: Tuple[str]) -> Dict[str, int]:
"""
Counts the number of characters in each string within a tuple of homograph strings.
Args:
words (Tuple[str]): A tuple co... |
evol_instruct_66k | 36,041 | Write a Python function to extract the first `n` elements from a given list of integers. The function should handle cases where `n` is greater than the length of the list by returning the entire list. The function should also handle cases where `n` is less than or equal to 0 by returning an empty list.
The code should... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_first_n_elements(num_list: List[int], n: int) -> List[int]:
"""
Extracts the first n elements from the given list of integers.
Args:
num_list (List[int]): The list of integers from w... |
evol_instruct_66k | 36,051 | Write a Python function to determine if all elements in a given list are identical. The function should return `True` if all elements are the same, and `False` otherwise. The code should start with:
```python
from typing import List
def all_elements_identical(arr: List[int]) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def all_elements_identical(arr: List[int]) -> bool:
"""
Determines if all elements in the given list are identical.
Args:
arr (List[int]): The list of integers to check.
Returns:
... |
evol_instruct_66k | 36,056 | Write a Python function to replace all instances of the character '0' with the character 'x' in a given two-dimensional grid of alphanumeric entities. The grid is represented as a list of lists, where each inner list represents a row in the grid. The function should modify the grid in place and return the modified grid... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def replace_zeros_with_x(grid: List[List[str]]) -> List[List[str]]:
"""
Replace all instances of the character '0' with the character 'x' in a given two-dimensional grid.
Args:
grid (List[Li... |
evol_instruct_66k | 36,068 | Write a Python function to count the occurrences of each type of fruit in a given list of fruits. The function should be efficient and concise, leveraging Python's standard library to achieve this. The code should start with:
```python
from typing import List, Dict
def count_fruits(fruit_basket: List[str]) -> Dict[str... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
from collections import Counter
def count_fruits(fruit_basket: List[str]) -> Dict[str, int]:
"""
Count the occurrences of each type of fruit in the given list.
Args:
fruit_basket (List... |
evol_instruct_66k | 36,083 | Write a Python function to swap corresponding elements between two lists of strings. The function should take two lists as input and return the two lists with their elements swapped at the same indices. If the lists are of different lengths, the function should return the original lists without any changes.
The code s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def swap_corresponding_elements(list1: List[str], list2: List[str]) -> (List[str], List[str]):
"""
Swaps corresponding elements between two lists of strings.
Args:
list1 (List[str]): The fir... |
evol_instruct_66k | 36,089 | Write a Python function to filter and group highly rated novels by their authors. The function should take a list of dictionaries, where each dictionary represents a novel with keys `title`, `rating`, and `author`. The function should return a dictionary where the keys are the authors and the values are lists of titles... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def group_highly_rated_novels(novels: List[Dict[str, any]]) -> Dict[str, List[str]]:
"""
Groups highly rated novels (rating >= 4.5) by their authors.
Args:
novels (List[Dict[str, any]]... |
evol_instruct_66k | 36,093 | Write a Python function to sum two values, ensuring that both values are numbers (either integers or floats). If either of the values is not a number, raise a `ValueError` with an appropriate message. The function should start with:
```python
def sum_of_two_values(a, b):
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_two_values(a, b):
"""
Sums two values, ensuring both are numbers (either integers or floats).
Args:
a: The first value to be summed.
b: The second value to be summed.
Returns:
The sum... |
evol_instruct_66k | 36,097 | Write a Python function to extract all user names and domain names from a list of given email addresses. The function should handle large numbers of email addresses and different domain formats. The code should start with:
```python
from typing import List, Tuple
def extract_user_domain(email_list: List[str]) -> Tuple... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def extract_user_domain(email_list: List[str]) -> Tuple[List[str], List[str]]:
"""
Extracts all user names and domain names from a list of given email addresses.
Args:
email_list (Lis... |
evol_instruct_66k | 36,099 | Write a Python function to create a composite data structure, specifically a dictionary, using two tuples that share a congruent number of constituent elements. The function should take two tuples as input and return a dictionary where each key-value pair is formed by corresponding elements from the two tuples.
The co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Dict
def create_composite_dict(tuple1: Tuple[str], tuple2: Tuple[str]) -> Dict[str, str]:
"""
Creates a dictionary from two tuples with congruent elements.
Args:
tuple1 (Tuple[str]): The f... |
evol_instruct_66k | 36,107 | Write a Python function to calculate the sum of elements in a provided list, but with an additional feature: if the list contains any negative numbers, the function should return the sum of the absolute values of those numbers instead. If the list contains no negative numbers, the function should return the sum of all ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_list_with_abs(input_list: List[int]) -> int:
"""
Calculate the sum of elements in a provided list. If the list contains any negative numbers,
return the sum of the absolute values of those nu... |
evol_instruct_66k | 36,115 | Write a Python function to sort a list of non-negative integers based on the lengths of their binary representations. If two numbers have the same binary length, they should be sorted by their decimal values. The function should handle large numbers efficiently.
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
def sort_by_binary_len(arr: List[int]) -> List[int]:
"""
Sorts a list of non-negative integers based on the lengths of their binary representations.
If two numbers have the same binary length, they a... |
evol_instruct_66k | 36,131 | Write a Python function to calculate the area of a circle given its radius. The function should include validation checks to ensure the radius is non-negative. If the radius is negative, the function should return `None`. The area should be computed to three decimal places.
The code should start with:
```python
def ca... | Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_circle_area(radius: float) -> float:
"""
Calculate the area of a circle given its radius.
Args:
radius (float): The radius of the circle.
Returns:
float: The area of the circle rounded to ... |
evol_instruct_66k | 36,135 | Write a Python function to print all the items in a given list in reverse order without using the built-in `reverse()` function, list slicing, or any other built-in functions that directly reverse the list. The function should iterate through the list in reverse order using a loop and print each item.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_reverse_list(items: List[str]) -> None:
"""
Prints all the items in the given list in reverse order without using the built-in reverse() function or list slicing.
Args:
items (List... |
evol_instruct_66k | 36,148 | Write a Python function to find and return all unique alphabetic characters from two given strings, which may contain both alphabetic and numeric characters. The function should return the unique alphabetic characters in sorted order.
The code should start with:
```python
from typing import List
def unique_alphabetic... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def unique_alphabetic_characters(string1: str, string2: str) -> List[str]:
"""
Find and return all unique alphabetic characters from two given strings.
Args:
string1 (str): The first input s... |
evol_instruct_66k | 36,169 | Write a Python function to sort a given list of integers using the cocktail shaker sort algorithm. The cocktail shaker sort, also known as bidirectional bubble sort, is a variation of the bubble sort that sorts the list in both directions, first from the beginning to the end (like a bubble sort), and then from the end ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def cocktail_shaker_sort(arr: List[int]) -> List[int]:
"""
Sorts a list of integers using the cocktail shaker sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
R... |
evol_instruct_66k | 36,177 | Write a Python function to validate a list of email addresses and classify them by their domains. The function should return a dictionary where each key is a domain and the value is a list of valid email addresses that belong to that domain. The function should use a regular expression to validate the email addresses.
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
import re
def validate_and_classify_emails(emails: List[str]) -> Dict[str, List[str]]:
"""
Validates a list of email addresses and classifies them by their domains.
Args:
emails (List[... |
evol_instruct_66k | 36,178 | Write a Python function to implement the bubble sort algorithm correctly. The function should sort a list of integers in ascending order. 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 a list of integers in ascending order using the bubble sort algorithm.
Args:
arr (List[int]): The list of integers to be sorted.
... |
evol_instruct_66k | 36,183 | Write a Python function to retrieve the terminal entity (either the first or the last element) from a given deque data structure. The function should accept a deque and a boolean flag indicating whether to retrieve the first element (`True`) or the last element (`False`). If the deque is empty, the function should retu... | Here is the Python code to solve the given problem in the markdown block:
```python
from collections import deque
from typing import Optional
def get_terminal_entity(d: deque, get_first: bool) -> Optional[int]:
"""
Retrieve the terminal entity (either the first or the last element) from a given deque.
Arg... |
evol_instruct_66k | 36,187 | Write a Python function to calculate the absolute difference between two given numbers. The function should take two integers as input and return the absolute difference between them. The code should start with:
```python
def absolute_difference(a: int, b: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def absolute_difference(a: int, b: int) -> int:
"""
Calculate the absolute difference between two integers.
Args:
a (int): The first integer.
b (int): The second integer.
Returns:
int: The absol... |
evol_instruct_66k | 36,191 | Write a Python function to create a random 3D array with provided dimensions and ensure that each layer's values are sorted in ascending order without any repeated numbers within each layer. The function should take three parameters: the number of layers, the number of rows, and the number of columns. The function shou... | Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
import random
def create_sorted_3d_array(layers: int, rows: int, columns: int) -> np.ndarray:
"""
Create a random 3D array with provided dimensions where each layer's values are sorted in ascending order with... |
evol_instruct_66k | 36,200 | Write a Python function that decrements a counter by 2 in each iteration of a loop and prints the current value of the counter. Additionally, if the counter value is divisible by 3, print a message indicating that the count is divisible by 3. The function should start with:
```python
def decrement_counter(start: int):
... | Here is the Python code to solve the given problem in the markdown block:
```python
def decrement_counter(start: int):
"""
Decrements a counter by 2 in each iteration of a loop and prints the current value of the counter.
If the counter value is divisible by 3, prints a message indicating that the count is ... |
evol_instruct_66k | 36,216 | Write a Python function to remove a specific key from a dictionary if it exists, and return the modified dictionary. The function should handle cases where the key does not exist without raising an error. The code should start with:
```python
from typing import Dict, Any, Optional
def remove_key(dictionary: Dict[Any, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any, Optional
def remove_key(dictionary: Dict[Any, Any], key_to_remove: Any) -> Optional[Dict[Any, Any]]:
"""
Removes a specific key from a dictionary if it exists and returns the modified dictionary.
... |
evol_instruct_66k | 36,218 | Write a Python function to reverse a given string. The function should take a string as input and return the reversed string. The code should start with:
```python
def reverse_string(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def reverse_string(s: str) -> str:
"""
Reverses the given string.
Args:
s (str): The string to be reversed.
Returns:
str: The reversed string.
"""
# Use slicing to reverse the string
rever... |
evol_instruct_66k | 36,220 | Write a Python function to convert a measurement of pressure from atmospheres (atm) to its equivalent in pascals (Pa). The conversion factor from atmospheres to pascals is 1 atm = 101325 Pa. The function should handle both positive and negative values of pressure in atmospheres.
The code should start with:
```python
d... | Here is the Python code to solve the given problem in the markdown block:
```python
def atm_to_pa(atm: float) -> float:
"""
Convert a measurement of pressure from atmospheres (atm) to pascals (Pa).
Args:
atm (float): The pressure in atmospheres.
Returns:
float: The equivalent pressure ... |
evol_instruct_66k | 36,223 | Write a Python function to separate a list of numbers into two lists: one containing all even numbers and the other containing all odd numbers. The function should use only the `filter()` function and list comprehensions or lambda functions. The code should start with:
```python
from typing import List, Tuple
def sepa... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def separate_evens_odds(numbers: List[int]) -> Tuple[List[int], List[int]]:
"""
Separates a list of numbers into two lists: one containing all even numbers and the other containing all odd numbers... |
evol_instruct_66k | 36,225 | Write a Python function to generate a list of odd integers within a specified range `[start, end]`. The function should return a list of odd numbers within the given range, inclusive of both `start` and `end`.
The code should start with:
```python
from typing import List
def generate_odd_numbers(start: int, end: 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 integers within the specified range [start, end].
Args:
start (int): The starting integer of the range... |
evol_instruct_66k | 36,226 | Write a Python function to extract elements with the values "Pineapple" and "Strawberries" from a given tuple without using built-in functions or libraries. The function should use algorithmic logic to achieve this.
The code should start with:
```python
from typing import Tuple, List
def extract_specific_elements(inp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, List
def extract_specific_elements(input_tuple: Tuple[str, ...]) -> List[str]:
"""
Extracts elements with the values "Pineapple" and "Strawberries" from the given tuple.
Args:
input_tuple ... |
evol_instruct_66k | 36,227 | Write a Python function to implement a modified merge sort algorithm that sorts an array of integers in ascending order with the following constraints:
1. Negative numbers should be sorted in ascending order and placed at the beginning of the array.
2. Positive numbers (including zero) should be sorted in ascending ord... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def modified_merge_sort(nums: List[int]) -> List[int]:
"""
Sorts an array of integers with the following constraints:
1. Negative numbers are sorted in ascending order and placed at the beginning of ... |
evol_instruct_66k | 36,231 | Write a Python function to calculate the sum of two user-defined variables and return the result. The function should take two integers as input and return their sum. The code should start with:
```python
def sum_of_two_numbers(var1: int, var2: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_two_numbers(var1: int, var2: int) -> int:
"""
Calculate the sum of two integers.
Args:
var1 (int): The first integer.
var2 (int): The second integer.
Returns:
int: The sum of var1 and... |
evol_instruct_66k | 36,233 | Write a Python function to filter out and return only the even numbers from a given list of integers. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def filter_even_numbers(num_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 filter_even_numbers(num_list: List[int]) -> List[int]:
"""
Filters out and returns only the even numbers from the given list of integers.
Args:
num_list (List[int]): A list of integers f... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.