source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
code_exercise_27k | 5,656 | Write a Python function to convert an octal number to a string representation of a binary number. The function should handle input validation to ensure the input is a valid octal number. The code should start with:
```python
def octal_to_binary(octal_number: int) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def octal_to_binary(octal_number: int) -> str:
"""
Convert an octal number to a string representation of a binary number.
Args:
octal_number (int): The octal number to convert.
Returns:
str: The string ... |
code_exercise_27k | 5,658 | Write a Python function to create a new list by multiplying elements of two given lists element by element. The function should handle lists of different lengths by padding the shorter list with zeros. The code should start with:
```python
from typing import List
def multiply_lists_with_padding(list1: List[int], list2... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def multiply_lists_with_padding(list1: List[int], list2: List[int]) -> List[int]:
"""
Multiplies corresponding elements of two lists, padding the shorter list with zeros to match the length of the longer... |
code_exercise_27k | 5,661 | Write a Python function to convert a string representation of a hexadecimal number to an octal number. The function should handle both uppercase and lowercase hexadecimal digits and should return the octal representation as a string. The function should also handle the optional '0x' prefix in the hexadecimal input.
Th... | Here is the Python code to solve the given problem in the markdown block:
```python
def hex_to_oct(hex_num: str) -> str:
"""
Convert a string representation of a hexadecimal number to an octal number.
Args:
hex_num (str): The hexadecimal number to be converted. It can be in uppercase or lowercase a... |
code_exercise_27k | 5,676 | Write a Python function to map each key in a dictionary to the length of its corresponding value, and then sort the dictionary based on these mapped lengths in ascending order. The function should return the sorted dictionary.
The code should start with:
```python
from typing import Dict
def sort_dict_by_value_length... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_value_length(dictionary: Dict[str, str]) -> Dict[str, int]:
"""
Maps each key in the dictionary to the length of its corresponding value,
and sorts the dictionary based on these mapp... |
code_exercise_27k | 5,677 | Write a Python function to find the largest number in a list that is smaller than a given value. The function should return `None` if no number in the list satisfies the condition. The code should start with:
```python
from typing import List, Optional
def find_largest_smaller_number(lst: List[int], value: int) -> Opt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_largest_smaller_number(lst: List[int], value: int) -> Optional[int]:
"""
Finds the largest number in a list that is smaller than a given value.
Args:
lst (List[int]): A li... |
code_exercise_27k | 5,682 | Write a Python function to create a new list where each element is the sum of corresponding elements from two given lists. If the input lists have different lengths, the function should raise a `ValueError`. The code should start with:
```python
from typing import List
def sum_lists(list1: List[int], list2: List[int])... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Create a new list where each element is the sum of corresponding elements from two given lists.
Args:
list1 (List[int]): F... |
code_exercise_27k | 5,686 | Write a Python function to find the frequency of all elements in a given list and sort them in descending order of their frequency. If two elements have the same frequency, they should appear in the order of their first occurrence in the original list.
The code should start with:
```python
from typing import List
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def frequency_sort(lst: List) -> List:
"""
Returns a list sorted in descending order of element frequency.
Args:
lst (List): A list of elements.
Returns:
List: A list of element... |
code_exercise_27k | 5,689 | Write a Python function to convert a given date and time string from one format to another. The function should take three parameters: the date and time string, the input format, and the desired output format. The function should return the formatted date and time string.
The code should start with:
```python
from dat... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def convert_date_time(date_string: str, input_format: str, output_format: str) -> str:
"""
Convert a date and time string from one format to another.
Args:
date_string (str): The input... |
code_exercise_27k | 5,690 | Write a Python function to find the indices of two elements in a list that add up to a given target value. If no such pair exists, the function should return an empty list. The function should be efficient and avoid using nested loops to ensure optimal performance.
The code should start with:
```python
from typing imp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_two_elements(nums: List[int], target: int) -> List[int]:
"""
Find the indices of two elements in a list that add up to a given target value.
Args:
nums (List[int]): The list of numb... |
code_exercise_27k | 5,691 | Write a Python function to map each key in a dictionary to its corresponding value's length, and sort the dictionary based on the mapped values in descending order. The function should return the sorted dictionary.
The code should start with:
```python
from typing import Dict
def sort_dict_by_value_length(dictionary:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_value_length(dictionary: Dict[str, str]) -> Dict[str, int]:
"""
Maps each key in a dictionary to its corresponding value's length and sorts the dictionary based on the mapped values in d... |
code_exercise_27k | 5,694 | Write a Python function to partition a list into two sublists, one containing all even elements and the other containing all odd elements. The function should return a tuple where the first element is the list of even numbers and the second element is the list of odd numbers. 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, Tuple
def partition_list(lst: List[int]) -> Tuple[List[int], List[int]]:
"""
Partition a list into two sublists, one for even elements and the other for odd elements.
Args:
lst (List[int]):... |
code_exercise_27k | 5,700 | Write a Python function to create a new list where each element is the sum of the first `n` elements from an existing list. If the length of the existing list is less than `n`, the function should return an empty list. The function should handle lists of integers and floats. The code should start with:
```python
from t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def create_sum_list(lst: List[Union[int, float]], n: int) -> List[Union[int, float]]:
"""
Create a new list where each element is the sum of the first n elements from an existing list.
Args:
... |
code_exercise_27k | 5,703 | Write a Python function to find the second smallest element in a given list of integers. The function should handle lists with at least two distinct elements and raise a `ValueError` if the list does not meet this requirement. The code should start with:
```python
from typing import List
def find_second_smallest(numbe... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_second_smallest(numbers: List[int]) -> int:
"""
Find the second smallest element in a list of integers.
Args:
numbers (List[int]): A list of integers.
Returns:
int: The... |
code_exercise_27k | 5,704 | Write a Python function to find the key-value pair in a dictionary that has the greatest sum of ASCII values for its value. The function should return a tuple containing the key and the value with the greatest sum of ASCII values. If the dictionary is empty, the function should raise a `ValueError`.
The code should st... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_max_ascii_pair(dictionary: dict) -> tuple:
"""
Finds the key-value pair with the greatest sum of ASCII values in the given dictionary.
Args:
dictionary (dict): The input dictionary where each value is a str... |
code_exercise_27k | 5,712 | Write a Python function to convert a string to its hexadecimal representation. The function should take a string as input and return a string of hexadecimal digits representing the bytes of the input string. The function should handle any valid string input and return the correct hexadecimal representation. The code sh... | Here is the Python code to solve the given problem in the markdown block:
```python
def string_to_hex(text: str) -> str:
"""
Convert a string to its hexadecimal representation.
Args:
text (str): The string to be converted to hexadecimal.
Returns:
str: The hexadecimal representation of ... |
code_exercise_27k | 5,714 | Write a Python function to check if a given list is a subsequence of another list. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. The function should return `True` if the first list is a subsequence of the secon... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_subsequence(subseq: List[int], seq: List[int]) -> bool:
"""
Check if the list `subseq` is a subsequence of the list `seq`.
Args:
subseq (List[int]): The subsequence to check.
... |
code_exercise_27k | 5,725 | Write a Python function to find the smallest missing positive integer in a given list of integers. The function should efficiently determine the smallest positive integer that is not present in the list. The code should start with:
```python
from typing import List
def find_smallest_missing_positive_integer(nums: List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_smallest_missing_positive_integer(nums: List[int]) -> int:
"""
Find the smallest missing positive integer in a list.
This function takes a list of integers as input and returns the smallest... |
code_exercise_27k | 5,727 | Write a Python function to create a new dictionary from a given dictionary, where each key-value pair is transformed into a tuple. The function should take a dictionary as input and return a new dictionary where each key in the original dictionary is mapped to a tuple containing the key and its corresponding value.
Th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def transform_dict_to_tuples(dictionary: Dict[Any, Any]) -> Dict[Any, tuple]:
"""
Transforms a given dictionary into a new dictionary where each key-value pair is converted into a tuple.
Args:
... |
code_exercise_27k | 5,730 | Write a Python function to encode a given plain text string using the ROT13 cipher. The ROT13 cipher is a simple letter substitution cipher that replaces a letter with the 13th letter after it in the alphabet. The function should only encode alphabetic characters (A-Z, a-z), while leaving other characters unchanged.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
def rot13_encode(plain_text: str) -> str:
"""
Encode a plain text string using the ROT13 cipher.
Parameters:
plain_text (str): The plain text string to be encoded.
Returns:
str: The ROT13 encoded string.
N... |
code_exercise_27k | 5,735 | Write a Python function to convert a list of characters to a string. The function should ensure that the input list contains only single-character strings. If the input list contains any non-character elements or is not a list, the function should raise appropriate exceptions.
The code should start with:
```python
fro... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def convert_list_to_string(char_list: List[str]) -> str:
"""
Convert a list of single-character strings to a single string.
Args:
char_list (List[str]): The list of single-character strings ... |
code_exercise_27k | 5,738 | Write a Python function to find the length of the longest increasing subsequence (LIS) in a given list of integers. The function should return the length of the LIS.
The code should start with:
```python
from typing import List
def longest_increasing_subsequence(nums: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_increasing_subsequence(nums: List[int]) -> int:
"""
Finds the length of the longest increasing subsequence in a list.
Args:
nums: A list of integers representing the input sequen... |
code_exercise_27k | 5,741 | Write a Python function to move all negative numbers to the beginning of a given list while maintaining the relative order of the non-negative numbers. The function should not change the order of the negative numbers among themselves. The code should start with:
```python
from typing import List
def move_negatives_to_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def move_negatives_to_front(lst: List[int]) -> List[int]:
"""
Move all negative numbers to the beginning of the given list while maintaining the relative order of the non-negative numbers.
Args:
... |
code_exercise_27k | 5,743 | Write a Python function to create a new list containing all elements of an existing list except the ones at odd indices. The function should be efficient and handle lists of varying lengths. The code should start with:
```python
from typing import List
def filter_even_indices(input_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_indices(input_list: List[int]) -> List[int]:
"""
Returns a new list containing all elements of the input list except the ones at odd indices.
Args:
input_list (List[int]): Th... |
code_exercise_27k | 5,746 | Write a Python function to generate all possible strings formed by concatenating `n` strings from a given set, without repeating any substring of length `k`, without using any character more than `max_char_count` times, and without using any substring more than `max_substring_count` times. The function should start wit... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Set
from itertools import combinations, permutations
def generate_valid_strings(strings: Set[str], n: int, k: int, max_char_count: int, max_substring_count: int) -> Set[str]:
"""
Generate all possible strings... |
code_exercise_27k | 5,749 | Write a Python function to find the largest sum of any contiguous subarray within a given list of integers. The function should efficiently handle both positive and negative numbers. The code should start with:
```python
from typing import List
def find_largest_sum_subarray(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_largest_sum_subarray(arr: List[int]) -> int:
"""
Find the largest sum of any contiguous subarray within a given list of integers.
Args:
arr (List[int]): The input list of integers.
... |
code_exercise_27k | 5,753 | Write a Python function to sort a list of lists based on the length of each sublist in descending order. If two sublists have the same length, they should remain in their original order relative to each other. The function should be efficient and handle various edge cases, such as an empty list or a list containing emp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_list_of_lists_descending(lst: List[List[int]]) -> List[List[int]]:
"""
Sorts a list of lists based on the length of each sublist in descending order.
Args:
lst (List[List[int]]): Th... |
code_exercise_27k | 5,754 | Write a Python function to convert a list of paragraphs into a single string with each paragraph separated by a newline character. The function should handle empty lists and lists with a single paragraph gracefully.
The code should start with:
```python
from typing import List
def convert_paragraphs_to_string(paragra... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def convert_paragraphs_to_string(paragraphs: List[str]) -> str:
"""
Converts a list of paragraphs into a single string with each paragraph separated by a newline character.
Args:
paragraphs ... |
code_exercise_27k | 5,762 | Write a Python function to convert a string into a list of substrings based on a specified delimiter. The function should handle cases where the delimiter is not present in the string, and it should also handle multiple consecutive delimiters by treating them as a single delimiter. 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 split_string(string: str, delimiter: str) -> List[str]:
"""
Convert a string into a list of substrings based on a specified delimiter.
Args:
string (str): The input string to be split.
... |
code_exercise_27k | 5,764 | Write a Python function to convert a list of substrings into a single string using a specified delimiter. The function should handle input validation to ensure that the substrings are provided as a list and the delimiter is a string. If the input is invalid, the function should raise a `TypeError`.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def convert_list_to_string(substrings: List[str], delimiter: str) -> str:
"""
Converts a list of substrings to a string based on a specified delimiter.
Args:
substrings (List[str]): A list o... |
code_exercise_27k | 5,767 | Write a Python function to convert a string into a list of strings based on a specified substring separator. The function should handle cases where the separator is not found in the string and should return the entire string as a single-element list. Additionally, the function should handle multiple occurrences of the ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def string_to_list(string: str, separator: str) -> List[str]:
"""
Convert a string to a list of strings separated by a specified substring.
Args:
string (str): The input string to be split.
... |
code_exercise_27k | 5,768 | Write a Python function to rearrange a list of numbers such that all even numbers appear before all odd numbers. The function should maintain the relative order of the even and odd numbers as they appear in the original list. The code should start with:
```python
from typing import List
def rearrange_even_odd(numbers:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def rearrange_even_odd(numbers: List[int]) -> List[int]:
"""
Rearranges the list of numbers such that all even numbers appear before all odd numbers.
The relative order of the even and odd numbers is... |
code_exercise_27k | 5,770 | Write a Python function to convert a list of strings into a single string, with each string separated by a specified substring. The function should handle cases where the list is empty or contains only one element. The code should start with:
```python
from typing import List
def join_strings_with_separator(strings: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def join_strings_with_separator(strings: List[str], separator: str) -> str:
"""
Convert a list of strings into a single string, with each string separated by a specified substring.
Args:
str... |
code_exercise_27k | 5,773 | Write a Python function to convert a given string into a list of characters in reverse order. The function should handle an empty string and return an empty list in that case. The function should also handle strings with special characters and spaces correctly.
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 reverse_string_to_list(string: str) -> List[str]:
"""
Convert a given string into a list of characters in reverse order.
Args:
string (str): The input string to be reversed.
Returns... |
code_exercise_27k | 5,777 | Write a Python function to find the intersection of two sets, `setA` and `setB`, and return the result as a new set. The function should handle cases where the sets are empty or have no common elements. The code should start with:
```python
def find_intersection(setA: set, setB: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_intersection(setA: set, setB: set) -> set:
"""
Finds the intersection of two sets.
Args:
setA (set): The first set.
setB (set): The second set.
Returns:
set: The intersection of setA an... |
code_exercise_27k | 5,779 | Write a Python function to convert a given string into a list of words in reverse order. The function should handle input validation to ensure the input is a string. If the input is not a string, it should raise a `TypeError`. The function should start with:
```python
from typing import List
def reverse_word_order(str... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_word_order(string: str) -> List[str]:
"""
Convert a given string into a list of words in reverse order.
Args:
string (str): The input string to be processed.
Returns:
... |
code_exercise_27k | 5,780 | Write a Python function to remove duplicate elements from a given list while preserving the order of the first occurrence of each element. The function should return a new list with the duplicates removed.
The code should start with:
```python
from typing import List
def remove_duplicates_preserve_order(lst: List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_preserve_order(lst: List[int]) -> List[int]:
"""
Remove duplicate elements from a given list while preserving the order of the first occurrence of each element.
Args:
l... |
code_exercise_27k | 5,782 | Write a Python function to convert a list of words in reverse order to a string, ensuring that the words are joined together with a specified delimiter. The function should handle cases where the list is empty or contains only one word.
The code should start with:
```python
from typing import List
def reverse_words_t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_words_to_string_with_delimiter(words: List[str], delimiter: str) -> str:
"""
Converts a list of words in reverse order to a string, joining the words with a specified delimiter.
Args:
... |
code_exercise_27k | 5,783 | Write a Python function to find the length of the longest bitonic subsequence in a given list. A bitonic subsequence is a sequence that first increases and then decreases. The function should start with:
```python
from typing import List
def longest_bitonic_subsequence_length(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_bitonic_subsequence_length(arr: List[int]) -> int:
"""
Find the length of the longest bitonic subsequence in the given list.
A bitonic subsequence is a sequence that first increases and ... |
code_exercise_27k | 5,784 | Write a Python function to check if a given set is a subset of another set. The function should handle the following:
1. Accept two sets as input.
2. Return `True` if the first set is a subset of the second set, otherwise return `False`.
3. Raise a `TypeError` if either of the inputs is not a set.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_subset(set1: set, set2: set) -> bool:
"""
Check if set1 is a subset of set2.
Parameters:
set1 (set): The set to be checked as a subset.
set2 (set): The superset to be checked against.
Returns:
bool: ... |
code_exercise_27k | 5,790 | Write a Python function to merge two sorted lists into a new list while maintaining the sorted order. The function should handle lists of integers and ensure that the input lists are sorted before merging. If either input list is not sorted, the function should raise a `ValueError`.
The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def merge_sorted_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Merge two sorted lists into a new list while maintaining sorted order.
Args:
list1 (List[int]): The first sorted ... |
code_exercise_27k | 5,794 | Write a Python function to convert a list of paragraphs in reverse order to a single string, with each paragraph separated by a newline character. The function should handle an empty list by returning an empty string.
The code should start with:
```python
from typing import List
def reverse_paragraphs_to_string(parag... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_paragraphs_to_string(paragraphs: List[str]) -> str:
"""
Converts a list of paragraphs in reverse order to a single string, with each paragraph separated by a newline character.
Args:
... |
code_exercise_27k | 5,798 | Write a Python function to check if all elements in a set are divisible by a given number. The function should return `True` if all elements in the set are divisible by the given number, and `False` otherwise. The function should handle empty sets by returning `True`.
The code should start with:
```python
def check_di... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_divisibility(nums: set, divisor: int) -> bool:
"""
Check if all elements in a set are divisible by a given number.
Args:
nums (set): A set of numbers to check.
divisor (int): The number to check di... |
code_exercise_27k | 5,804 | Write a Python function to find the symmetric difference between two sets. The symmetric difference of two sets is the set of elements which are in either of the sets but not in both. The function should take two sets as input and return a new set containing the symmetric difference.
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
def symmetric_difference(set1: set, set2: set) -> set:
"""
Finds the symmetric difference between two sets.
The symmetric difference of two sets is the set of elements which are in either of the sets but not in both.
A... |
code_exercise_27k | 5,808 | Write a Python function to check if two sets are disjoint (have no common elements). The function should return `True` if the sets have no common elements, and `False` otherwise. The code should start with:
```python
def are_disjoint(set1: set, set2: set) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def are_disjoint(set1: set, set2: set) -> bool:
"""
Check if two sets are disjoint (have no common elements).
Args:
set1 (set): The first set to compare.
set2 (set): The second set to compare.
Returns:
... |
code_exercise_27k | 5,809 | Write a Python function to sort a dictionary in descending order based on its values. The function should return a new dictionary with the same keys but sorted by their corresponding values in descending order. The code should start with:
```python
from typing import Dict
def sort_dictionary_by_values(dictionary: Dict... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dictionary_by_values(dictionary: Dict[str, int]) -> Dict[str, int]:
"""
Sorts a dictionary in descending order based on its values.
Args:
dictionary (Dict[str, int]): The dictionary... |
code_exercise_27k | 5,812 | Write a Python function to sort a dictionary of strings by its keys in alphabetical order. The function should return a new dictionary with the keys sorted in alphabetical order, while preserving the original dictionary's values. The code should start with:
```python
from typing import Dict
def sort_dictionary_by_keys... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dictionary_by_keys(dictionary: Dict[str, any]) -> Dict[str, any]:
"""
Sorts a dictionary of strings by its keys in alphabetical order.
Args:
dictionary (Dict[str, any]): The diction... |
code_exercise_27k | 5,815 | Write a Python function to sort a dictionary of numbers in ascending order based on their values. The function should return a new dictionary with the same keys but with the values sorted in ascending order. The original dictionary should not be modified.
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 sort_dictionary_by_value(dictionary: Dict[int, int]) -> Dict[int, int]:
"""
Sorts a dictionary of numbers in ascending order based on their values and returns a new dictionary.
Args:
dic... |
code_exercise_27k | 5,818 | Write a Python function to create a new list where each element is the sum of the last `n` elements from an existing list. The function should handle cases where the length of the existing list is less than `n` by returning an empty list. The function should also handle cases where `n` is zero by returning a list of ze... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def create_new_list(lst: List[int], n: int) -> List[int]:
"""
Create a new list where each element is the sum of the last n elements from an existing list.
Args:
lst (List[int]): The existin... |
code_exercise_27k | 5,820 | Write a Python function to sort a dictionary based on the length of its values in ascending order. The function should return a new dictionary with the same keys but sorted values. The code should start with:
```python
from typing import Dict, Any
def sort_dict_by_value_length(dictionary: Dict[Any, list]) -> Dict[Any,... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def sort_dict_by_value_length(dictionary: Dict[Any, list]) -> Dict[Any, list]:
"""
Sorts a dictionary based on the length of its values in ascending order.
Args:
dictionary (Dict[Any, l... |
code_exercise_27k | 5,821 | Write a Python function to determine if a given set `A` is a proper subset of another set `B`. A set `A` is considered a proper subset of `B` if all elements of `A` are in `B`, but `A` is not equal to `B`.
The code should start with:
```python
def is_proper_subset(A: set, B: set) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_proper_subset(A: set, B: set) -> bool:
"""
Determine if set A is a proper subset of set B.
Args:
A (set): The first set to compare.
B (set): The second set to compare.
Returns:
bool: True... |
code_exercise_27k | 5,823 | Write a Python function to sort a dictionary in descending order based on the sum of its keys and values. The function should handle dictionaries where both keys and values are integers. The code should start with:
```python
from typing import Dict
def sort_dictionary_by_sum(dictionary: Dict[int, int]) -> Dict[int, in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dictionary_by_sum(dictionary: Dict[int, int]) -> Dict[int, int]:
"""
Sorts a dictionary in descending order based on the sum of its keys and values.
Args:
dictionary (Dict[int, int]... |
code_exercise_27k | 5,825 | Write a Python function to find the symmetric difference between two sets. The symmetric difference of two sets is defined as the set of elements that are present in either one of the sets, but not in both. The function should handle sets of any size and type of elements. The code should start with:
```python
def symme... | Here is the Python code to solve the given problem in the markdown block:
```python
def symmetric_difference(set1: set, set2: set) -> set:
"""
Calculate the symmetric difference between two sets.
The symmetric difference of two sets is the set of elements that are
present in either one of the sets, but... |
code_exercise_27k | 5,827 | Write a Python function to sort a dictionary based on the sum of the lengths of its keys and values. The function should return the sorted dictionary. The code should start with:
```python
from typing import Dict
def sort_dictionary_by_sum_length(dictionary: Dict[str, str]) -> Dict[str, str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dictionary_by_sum_length(dictionary: Dict[str, str]) -> Dict[str, str]:
"""
Sorts a dictionary based on the sum of the lengths of its keys and values.
Args:
dictionary (Dict[str, st... |
code_exercise_27k | 5,831 | Write a Python function to sort a dictionary based on the number of vowels in its values in descending order. The function should return a new dictionary with the same keys and values as the input dictionary, but sorted according to the number of vowels in the values. The code should start with:
```python
from typing i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_vowel_count(input_dict: Dict[str, str]) -> Dict[str, str]:
"""
Sorts a dictionary based on the number of vowels in its values in descending order.
Args:
input_dict (Dict[str... |
code_exercise_27k | 5,832 | Write a Python function to calculate the sum of all elements in 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 sum_of_list_elements(integers: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_list_elements(integers: List[int]) -> int:
"""
Calculates the sum of all elements in a given list of integers.
Args:
integers (List[int]): A list of integers.
Returns:
... |
code_exercise_27k | 5,834 | Write a Python function to sort a dictionary based on the first character of its values in ascending order. If two values start with the same character, their order should be preserved according to their original order in the dictionary. The function should return a new dictionary with the sorted key-value pairs.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_values(dict_obj: Dict[str, str]) -> Dict[str, str]:
"""
Sorts a dictionary based on the first character of its values in ascending order.
Args:
dict_obj (Dict[str, str]): Th... |
code_exercise_27k | 5,839 | Write a Python function to sort a dictionary based on the second character of its keys in descending order. If a key has fewer than two characters, it should be sorted by the first character. The function should handle dictionaries with string keys and any type of values. 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 Dict, Any
def sort_dict_by_second_char(dictionary: Dict[str, Any]) -> Dict[str, Any]:
"""
Sorts a dictionary based on the second character of its keys in descending order.
If a key has fewer than two char... |
code_exercise_27k | 5,840 | Write a Python function to find the frequency of a specific element in a given list of integers. The function should return the count of occurrences of the specified element in the list.
The code should start with:
```python
from typing import List
def count_element_frequency(lst: List[int], element: int) -> int:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_element_frequency(lst: List[int], element: int) -> int:
"""
Count the frequency of a specific element in a list of integers.
Args:
lst (List[int]): The list of integers to be check... |
code_exercise_27k | 5,841 | Write a Python function to sort a dictionary of tuples based on the second element of each tuple in ascending order. The function should return the sorted dictionary. The code should start with:
```python
from typing import Dict, Tuple
def sort_dict_by_second_element(dictionary: Dict[str, Tuple[int, int]]) -> Dict[str... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
def sort_dict_by_second_element(dictionary: Dict[str, Tuple[int, int]]) -> Dict[str, Tuple[int, int]]:
"""
Sorts a dictionary of tuples based on the second element of each tuple in ascending order... |
code_exercise_27k | 5,842 | Write a Python function to check if all elements in a given set are positive. The function should return `True` if all elements are positive, and `False` otherwise. The function should handle sets of integers and return `True` for an empty set.
The code should start with:
```python
def all_positive_elements(s: set) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
def all_positive_elements(s: set) -> bool:
"""
Check if all elements in a set are positive.
Args:
s (set): The set of integers to be checked.
Returns:
bool: True if all elements in the set are positive,... |
code_exercise_27k | 5,845 | Write a Python function to add all the even numbers between 1 and a given integer `n` to a set `A`. The function should return the updated set `A` containing the original elements along with the newly added even numbers. The code should start with:
```python
def add_even_numbers_to_set(A: set, n: int) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def add_even_numbers_to_set(A: set, n: int) -> set:
"""
Adds all even numbers between 1 and n to the set A.
Args:
A (set): The input set to which even numbers will be added.
n (int): The upper limit for addi... |
code_exercise_27k | 5,846 | Write a Python function to sort a dictionary based on the frequency of its values in descending order. If two values have the same frequency, the original order of the keys should be maintained. The function should return the sorted dictionary.
The code should start with:
```python
from typing import Dict
def sort_di... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_value_frequency(dictionary: Dict) -> Dict:
"""
Sort a dictionary based on the frequency of its values in descending order.
If two values have the same frequency, the original order o... |
code_exercise_27k | 5,847 | Write a Python function to round each element of a given list of floating-point numbers to a specified number of decimal places. The function should return a new list containing the rounded values. The code should start with:
```python
from typing import List
def round_list_elements(lst: List[float], decimal_places: i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def round_list_elements(lst: List[float], decimal_places: int) -> List[float]:
"""
Rounds each element of the input list to the specified number of decimal places.
Args:
lst (List[float]): A... |
code_exercise_27k | 5,851 | Write a Python function to sort a dictionary based on the sum of the ASCII values of the first and last characters of its keys and values. The function should return a new dictionary with the sorted key-value pairs. The code should start with:
```python
from typing import Dict
def sort_dict_by_ascii_sum(dictionary: Di... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_ascii_sum(dictionary: Dict[str, str]) -> Dict[str, str]:
"""
Sort a dictionary based on the sum of the ASCII values of the first and last characters of its keys and values.
Args:
... |
code_exercise_27k | 5,853 | Write a Python function to interleave two given lists of arbitrary lengths. The function should create a new list by alternating elements from the two input lists. If one list is longer than the other, the remaining elements of the longer list should be appended to the end of the interleaved list.
The code should star... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def interleave_lists(list1: List[Any], list2: List[Any]) -> List[Any]:
"""
Interleave two given lists to create a new list.
Args:
list1 (List[Any]): The first list.
list2 (List[... |
code_exercise_27k | 5,854 | Write a Python function to sort a dictionary of dictionaries based on the length of the values in each nested dictionary in descending order. The function should return the sorted dictionary.
The code should start with:
```python
from typing import Dict
def sort_dict_of_dicts(d: Dict[str, Dict[str, int]]) -> Dict[str... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_of_dicts(d: Dict[str, Dict[str, int]]) -> Dict[str, Dict[str, int]]:
"""
Sorts a dictionary of dictionaries based on the length of the values in each nested dictionary in descending order.
... |
code_exercise_27k | 5,857 | Write a Python function to find the smallest missing positive integer that is not present in a given list of integers. The function should efficiently handle lists with both positive and negative integers, and should return the smallest positive integer that is not in the list.
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 find_smallest_missing_positive(lst: List[int]) -> int:
"""
Finds the smallest missing positive integer that is not present in a list.
Args:
lst (List[int]): A list of integers.
Retu... |
code_exercise_27k | 5,859 | Write a Python function to sort a dictionary based on the mean value of the numbers in its values in ascending order. The function should handle dictionaries where each value is a list of numbers. The function should return a new dictionary with the same keys and values, but sorted by the mean value of the lists in asc... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def sort_dict_by_mean(dictionary: Dict[str, List[int]]) -> Dict[str, List[int]]:
"""
Sorts a dictionary based on the mean value of the numbers in its values in ascending order.
Args:
d... |
code_exercise_27k | 5,861 | Write a Python function to find the kth smallest consecutive difference between any two elements in a given list of integers. The function should return the kth smallest difference. The code should start with:
```python
from typing import List
def find_kth_smallest_difference(lst: List[int], k: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_kth_smallest_difference(lst: List[int], k: int) -> int:
"""
Find the kth smallest consecutive difference between any two elements in a list.
Args:
lst (List[int]): The input list of... |
code_exercise_27k | 5,863 | Write a Python function to sort a dictionary based on the number of unique characters in its keys and values. The function should return the sorted dictionary. The code should start with:
```python
from typing import Dict
def sort_dict_by_unique_chars(dictionary: Dict[str, str]) -> Dict[str, str]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_unique_chars(dictionary: Dict[str, str]) -> Dict[str, str]:
"""
Sorts a dictionary based on the number of unique characters in its keys and values.
Args:
dictionary (Dict[st... |
code_exercise_27k | 5,864 | Write a Python function to find the set of elements that are present in the first set but not in the second set, and vice versa. The function should return a tuple containing two sets: the first set contains elements in the first set but not in the second set, and the second set contains elements in the second set but ... | Here is the Python code to solve the given problem in the markdown block:
```python
def symmetric_difference_sets(A: set, B: set) -> tuple:
"""
Finds the symmetric difference between two sets A and B.
Args:
A (set): The first set.
B (set): The second set.
Returns:
tuple: A tupl... |
code_exercise_27k | 5,865 | Write a Python function to swap the first and last elements of a given list. The function should return a new list with the elements swapped, while the original list remains unchanged. If the list has fewer than two elements, it should return the list as is.
The code should start with:
```python
from typing import Lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def swap_first_and_last_elements(lst: List[int]) -> List[int]:
"""
Swaps the first and last elements of a given list and returns a new list with the elements swapped.
Args:
lst (List[int]): ... |
code_exercise_27k | 5,868 | Write a Python function to sort a dictionary of strings based on the most frequently occurring character in each string. If two strings have the same most frequent character, the original order of the dictionary should be maintained. The function should start with:
```python
from typing import Dict
def sort_dict_by_mo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
from collections import Counter
def sort_dict_by_most_frequent_char(dictionary: Dict[str, str]) -> Dict[str, str]:
"""
Sorts a dictionary of strings based on the most frequently occurring character in ea... |
code_exercise_27k | 5,871 | Write a Python function to sort a dictionary of lists based on the maximum value in each list. The function should return the sorted dictionary. The code should start with:
```python
from typing import Dict, List
def sort_dict_by_max_value(dictionary: Dict[str, List[int]]) -> Dict[str, List[int]]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def sort_dict_by_max_value(dictionary: Dict[str, List[int]]) -> Dict[str, List[int]]:
"""
Sorts a dictionary of lists based on the maximum value in each list.
Args:
dictionary (Dict[st... |
code_exercise_27k | 5,873 | Write a Python function to remove duplicate elements from a given list while preserving the order of the first occurrence of each element. The function should return a new list containing only the unique elements in the order they first appear in the input list.
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 get_unique_elements_preserve_order(lst: List[int]) -> List[int]:
"""
Returns a list of unique elements from the input list, preserving the order of their first occurrence.
Args:
lst (Lis... |
code_exercise_27k | 5,875 | Write a Python function to find the set of elements that are only in one of the given sets (exclusive elements). The function should take two sets as input and return a set containing elements that are present in exactly one of the sets. The code should start with:
```python
def find_exclusive_elements(set_a: set, set_... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_exclusive_elements(set_a: set, set_b: set) -> set:
"""
Find the set of elements that are only in one of the sets (exclusive elements).
Args:
set_a (set): The first set.
set_b (set): The second set.
... |
code_exercise_27k | 5,877 | Write a Python function to find the k-th largest element in a given list of integers. The function should efficiently handle the task using a min-heap to maintain the k largest elements. The code should start with:
```python
from typing import List
import heapq
def find_kth_largest(numbers: List[int], k: int) -> int:
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import heapq
def find_kth_largest(numbers: List[int], k: int) -> int:
"""
Find the k-th largest element in a list of integers using a min-heap.
Args:
numbers (List[int]): The list of integer... |
code_exercise_27k | 5,878 | Write a Python function to find the difference between set A and the intersection of sets A and B. The function should return a new set containing elements that are in set A but not in the intersection of sets A and B.
The code should start with:
```python
def difference_of_sets(a: set, b: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def difference_of_sets(a: set, b: set) -> set:
"""
Calculate the difference between set A and the intersection of sets A and B.
Args:
a (set): The set A.
b (set): The set B.
Returns:
set: The di... |
code_exercise_27k | 5,879 | Write a Python function to sort a dictionary of dictionaries based on the sum of the values in each nested dictionary. The function should return a new dictionary with the same keys as the input dictionary, but with the nested dictionaries sorted in ascending order based on the sum of their values.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_nested_dict(dictionary: Dict[str, Dict[str, int]]) -> Dict[str, Dict[str, int]]:
"""
Sorts a dictionary of dictionaries based on the sum of the values in each nested dictionary.
Args:
... |
code_exercise_27k | 5,880 | Write a Python function to sort a list of floats in descending order. The function should handle lists of any length, including empty lists. The code should start with:
```python
from typing import List
def sort_floats_descending(nums: List[float]) -> List[float]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_floats_descending(nums: List[float]) -> List[float]:
"""
Sorts a list of floats in descending order.
Args:
nums (List[float]): A list of floats to be sorted.
Returns:
L... |
code_exercise_27k | 5,882 | Write a Python function to check if all elements in a given set are prime numbers. The function should return `True` if all elements are prime and `False` otherwise. The function should handle sets of integers and efficiently determine the primality of each number.
The code should start with:
```python
def check_prime... | Here is the Python code to solve the given problem in the markdown block:
```python
def check_prime_numbers(numbers: set) -> bool:
"""
Check if all elements in a set are prime numbers.
Args:
numbers (set): A set of integers to be checked for primality.
Returns:
bool: True if all elemen... |
code_exercise_27k | 5,888 | Write a Python function to sort a dictionary of tuples based on the product of the elements in each tuple. The function should return the sorted dictionary. The code should start with:
```python
from typing import Dict, Tuple
def sort_dictionary_by_product(my_dict: Dict[str, Tuple[int, ...]]) -> Dict[str, Tuple[int, .... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple
def sort_dictionary_by_product(my_dict: Dict[str, Tuple[int, ...]]) -> Dict[str, Tuple[int, ...]]:
"""
Sorts a dictionary of tuples based on the product of the elements in each tuple.
Args:
... |
code_exercise_27k | 5,889 | Write a Python function to remove an element from a list at a specific index and return the modified list. The function should handle cases where the index is out of range by raising an `IndexError` with a custom message.
The code should start with:
```python
from typing import List
def remove_element_from_list(lst: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_element_from_list(lst: List[int], index: int) -> List[int]:
"""
Remove an element from a list at a specific index and return the modified list.
Args:
lst (List[int]): The list fro... |
code_exercise_27k | 5,891 | Write a Python function to find the maximal and minimal elements in a given set. The function should handle sets of integers and return a tuple containing the maximal and minimal elements. If the set is empty, the function should raise a `ValueError`.
The code should start with:
```python
def find_max_min(s: set) -> t... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_max_min(s: set) -> tuple:
"""
Find the maximal and minimal elements in a given set.
Args:
s (set): The set to search for maximal and minimal elements.
Returns:
tuple: A tuple containing the max... |
code_exercise_27k | 5,893 | Write a Python function to sort a dictionary based on the number of occurrences of a specific word in its values. The function should return the sorted dictionary with keys ordered by the descending count of the specified word in their corresponding values.
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 sort_dict_by_word_count(dictionary: Dict[str, str], word: str) -> Dict[str, str]:
"""
Sorts a dictionary based on the number of occurrences of a specific word in its values.
Args:
dictio... |
code_exercise_27k | 5,894 | Write a Python function to check if a given list of integers is a palindrome. A list is considered a palindrome if it reads the same backward as forward. The function should return `True` if the list is a palindrome and `False` otherwise. The code should start with:
```python
from typing import List
def is_palindrome_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_palindrome_list(numbers: List[int]) -> bool:
"""
Check if a list of integers is a palindrome.
A list is considered a palindrome if it reads the same backward as forward.
Args:
nu... |
code_exercise_27k | 5,895 | Write a Python function to sort a dictionary of strings based on the last character of each string. The function should return a new dictionary with the same key-value pairs but sorted by the last character of the keys. The code should start with:
```python
from typing import Dict
def sort_dict_by_last_char(dictionary... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_last_char(dictionary: Dict[str, str]) -> Dict[str, str]:
"""
Sorts a dictionary of strings based on the last character of each string.
Args:
dictionary (Dict[str, str]): The... |
code_exercise_27k | 5,899 | Write a Python function to sort a dictionary based on the average length of its keys and values. The function should return a new dictionary with the same key-value pairs, but sorted based on the average length of the keys and values. The code should start with:
```python
from typing import Dict
def sort_dict_by_avera... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_average_length(dictionary: Dict[str, str]) -> Dict[str, str]:
"""
Sorts a dictionary based on the average length of its keys and values.
Args:
dictionary (Dict[str, str]): T... |
code_exercise_27k | 5,902 | Write a Python function to create a new list where each element is the sum of all distinct subarrays of an existing list. The function should return a list of integers where each element is the sum of all distinct subarrays of the input list. The code should start with:
```python
from typing import List
def create_sub... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def create_subarray_sums(nums: List[int]) -> List[int]:
"""
Creates a new list where each element is the sum of all distinct subarrays of the given list.
Args:
nums (List[int]): A list of in... |
code_exercise_27k | 5,905 | Write a Python function to check if a given set is a proper superset of multiple sets. A set is considered a proper superset of another set if it contains all elements of the other set and at least one additional element. The function should return `True` if the given set is a proper superset of all the other sets prov... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_proper_superset(set1, *other_sets) -> bool:
"""
Checks if a given set is a proper superset of multiple sets.
Parameters:
- set1: The set to check if it is a proper superset.
- *other_sets: Any number ... |
code_exercise_27k | 5,906 | Write a Python function to find the second smallest element in a given list of integers. If the list has fewer than two elements, the function should return `None`. The function should handle duplicate values and ensure that the second smallest element is correctly identified.
The code should start with:
```python
fro... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_second_smallest(nums: List[int]) -> Optional[int]:
"""
Find the second smallest element in a list of integers.
Args:
nums (List[int]): A list of integers.
Returns:
... |
code_exercise_27k | 5,913 | Write a Python function to check if a given set is a subset of multiple sets. The function should accept a variable number of sets as arguments and return `True` if the given set is a subset of all the other sets, and `False` otherwise. The code should start with:
```python
def is_subset_of_multiple_sets(given_set: set... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_subset_of_multiple_sets(given_set: set, *sets: set) -> bool:
"""
Check if a given set is a subset of multiple sets.
Args:
given_set (set): The set to check if it is a subset.
*sets (set): Variable num... |
code_exercise_27k | 5,917 | Write a Python function to find the length of the longest common subarray between two given lists. A subarray is a contiguous sequence of elements within a list. The function should return the length of the longest subarray that appears in both lists.
The code should start with:
```python
from typing import List
def ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_common_subarray_length(list1: List[int], list2: List[int]) -> int:
"""
Finds the length of the longest common subarray between two lists.
Args:
list1 (List[int]): The first l... |
code_exercise_27k | 5,919 | Write a Python function to sort a dictionary based on the number of four-letter words in its values. The dictionary's values are lists of words. The function should return a new dictionary sorted in ascending order based on the number of four-letter words in its values.
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 Dict, List
def sort_dict_by_four_letter_words(dictionary: Dict[str, List[str]]) -> Dict[str, List[str]]:
"""
Sorts a dictionary based on the number of four-letter words in its values.
Args:
dicti... |
code_exercise_27k | 5,920 | Write a Python function to split a list of items into two separate lists based on a given condition. The function should take a list of items and a callable (function) that returns a boolean value when applied to each item. The function should return a tuple containing two lists: the first list contains items that sati... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable, Tuple
def split_list(items: List, condition: Callable[[any], bool]) -> Tuple[List, List]:
"""
Split the elements of a list into two separate lists based on a condition.
Args:
item... |
code_exercise_27k | 5,923 | Write a Python function to sort a dictionary based on the sum of the ASCII values of its keys and values. The function should return a new dictionary with the same key-value pairs but sorted in ascending order based on the sum of the ASCII values of the keys and values.
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 Dict
def sort_dictionary_by_ascii_sum(dictionary: Dict[str, str]) -> Dict[str, str]:
"""
Sorts a dictionary based on the sum of ASCII values of keys and values.
Args:
dictionary (Dict[str, str]):... |
code_exercise_27k | 5,924 | 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(numbers: 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(numbers: List[int]) -> List[int]:
"""
Removes all even numbers from a given list of integers and returns a new list containing only the odd numbers.
Args:
numbers (Li... |
code_exercise_27k | 5,925 | Write a Python function to find the maximum and minimum element in the symmetric difference of two sets. The symmetric difference of two sets is the set of elements which are in either of the sets but not in both. The function should return a tuple containing the maximum and minimum elements of the symmetric difference... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_max_min_symmetric_difference(set1: set, set2: set) -> tuple:
"""
Find the maximum and minimum element in the symmetric difference of two sets.
Args:
set1 (set): The first set.
set2 (set): The second... |
code_exercise_27k | 5,926 | Write a Python function to sort a dictionary of tuples based on the sum of the second and third elements of each tuple. The function should return the sorted dictionary. The code should start with:
```python
from typing import Dict, Tuple, List
def sort_dict_by_sum_of_elements(dictionary: Dict[str, Tuple[int, int, int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Tuple, List
def sort_dict_by_sum_of_elements(dictionary: Dict[str, Tuple[int, int, int]]) -> Dict[str, Tuple[int, int, int]]:
"""
Sorts a dictionary of tuples based on the sum of the second and third el... |
code_exercise_27k | 5,928 | Write a Python function to find the maximum element in a nested list of integers. The function should handle nested lists of arbitrary depth and ensure that all elements are integers. If the list is empty or contains non-integer values, the function should raise a `ValueError`.
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 find_maximum_element(nested_list: List[List[int]]) -> int:
"""
Finds the maximum element among all nested lists in the provided list.
Args:
nested_list (List[List[int]]): A nested list o... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.