source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
code_exercise_27k | 6,605 | Write a Python function to remove all key-value pairs from a given dictionary where the keys are divisible by a specified divisor. The function should take two parameters: the dictionary and the divisor. The function should return the modified dictionary after removing the key-value pairs.
The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def remove_keys_divisible_by(dictionary: Dict[int, any], divisor: int) -> Dict[int, any]:
"""
Remove key-value pairs from a dictionary where the keys are divisible by a specified divisor.
Args:
... |
code_exercise_27k | 6,607 | Write a Python function to generate a list of the first `n` Fibonacci numbers using list comprehension. The function should start with:
```python
from typing import List
def generate_fibonacci_list(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_list(n: int) -> List[int]:
"""
Generate a list of the first n Fibonacci numbers using list comprehension.
Args:
n (int): The number of Fibonacci numbers to generate.
... |
code_exercise_27k | 6,609 | Write a Python function to count the number of occurrences of a specific element in a given list. The function should be able to handle lists containing elements of any type, including nested lists. The code should start with:
```python
from typing import List, Any
def count_occurrences(lst: List[Any], element: Any) -... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def count_occurrences(lst: List[Any], element: Any) -> int:
"""
Count the number of occurrences of a specific element in a list, including nested lists.
Args:
lst (List[Any]): The input... |
code_exercise_27k | 6,610 | Write a Python function to find the mode(s) of a given list using a list comprehension. The mode is the value(s) that appear most frequently in the list. If there are multiple values with the same highest frequency, the function should return all of them. The function should raise a `ValueError` if the input list is em... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_modes(data: List[int]) -> List[int]:
"""
Returns a list of mode(s) from a given list.
Args:
data (List[int]): The list of values to find the mode(s) from.
Returns:
List[... |
code_exercise_27k | 6,611 | Write a Python function to merge two dictionaries by combining their values as lists, giving priority to the values of the first dictionary. If a key exists in both dictionaries, the value from the first dictionary should be the first element in the combined list. If the value in either dictionary is already a list, it... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def merge_dictionaries(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, Any]:
"""
Merge two dictionaries by combining their values as lists, giving priority to the values of the first dict... |
code_exercise_27k | 6,615 | Write a Python function to flatten a nested dictionary into a single-level dictionary. The function should handle nested dictionaries of arbitrary depth and use a specified separator to concatenate keys from different levels. The function should also handle cases where the nested dictionary contains non-dictionary valu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def flatten_nested_dict(nested_dict: Dict[str, Any], sep: str = '_') -> Dict[str, Any]:
"""
Flatten a nested dictionary into a single-level dictionary.
Args:
nested_dict (Dict[str, Any]... |
code_exercise_27k | 6,618 | Write a Python function to sort a list of integers in ascending order using the selection sort algorithm. The function should not use any built-in sorting functions. The code should start with:
```python
from typing import List
def selection_sort(lst: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def selection_sort(lst: List[int]) -> List[int]:
"""
Sorts a given list of integers in ascending order using the selection sort algorithm.
Args:
lst (List[int]): The list of integers to be s... |
code_exercise_27k | 6,621 | Write a Python function to create a list and append multiple new elements to it. The function should accept a variable number of arguments and return the updated list with all the elements appended.
The code should start with:
```python
from typing import List, Any
def append_multiple_elements(elements: List[Any]) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def append_multiple_elements(elements: List[Any]) -> List[Any]:
"""
Create a list and append multiple new elements to it.
Args:
elements (List[Any]): A list of elements to be appended t... |
code_exercise_27k | 6,625 | Write a Python function to insert a new element at a specified position in a given list. The function should take three arguments: the list, the new element, and the position at which the element should be inserted. The position should be a non-negative integer. If the position is greater than the length of the list, t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def insert_element_at_position(lst: List[Any], element: Any, position: int) -> List[Any]:
"""
Inserts a new element at a specified position in the given list.
Args:
lst (List[Any]): The... |
code_exercise_27k | 6,628 | Write a Python function to calculate the number of months between two given dates. The function should handle the following:
1. Accept two `date` objects as input.
2. Ensure that the start date is before the end date.
3. Calculate the number of months between the two dates.
4. Return the number of months as an integer.... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import date
def calculate_months_between_dates(start_date: date, end_date: date) -> int:
"""
Calculate the number of months between two given dates.
Args:
start_date (date): The start date.
en... |
code_exercise_27k | 6,630 | Write a Python function to split a list into sublists of a specified length. If the length of the input list is not a multiple of the specified sublist length, the function should return the largest possible sublists, with the last sublist containing the remaining elements. The function should handle edge cases such as... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def split_list_into_sublists(lst: List[int], sublist_length: int) -> List[List[int]]:
"""
Split a list into sublists of a specified length.
Args:
lst (List[int]): The input list to be split.... |
code_exercise_27k | 6,633 | Write a Python function to find the first occurrence of a specific element in a given list and return its index. If the element is not found, return -1. The function should handle lists of any type of elements, including integers, strings, and other objects.
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, Any
def find_element_index(element: Any, lst: List[Any]) -> int:
"""
Find the index of the first occurrence of a specific element in a given list.
Args:
element (Any): The element to search... |
code_exercise_27k | 6,636 | Write a Python function to reverse the order of elements in a given list. The function should return a new list with the elements in reversed order, without modifying the original list. The code should start with:
```python
from typing import List
def reverse_list(arr: List) -> List:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_list(arr: List) -> List:
"""
Reverses the order of elements in a given list and returns a new list with the elements in reversed order.
Args:
arr (List): The input list to be rev... |
code_exercise_27k | 6,637 | Write a Python function to format and display the current date and time according to a given format string. The function should accept a format string as an argument and return the formatted date and time as a string. The format string should support the following directives:
- `%Y`: 4-digit year (e.g., 2022)
- `%y`: 2... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def format_current_datetime(format_str: str) -> str:
"""
Formats the current date and time according to the specified format string.
Args:
format_str (str): The format string for displaying the date... |
code_exercise_27k | 6,638 | Write a Python function to sort a list of numbers in descending order without modifying the original list. The function should return a new list with the numbers sorted in descending order.
The code should start with:
```python
from typing import List
def sort_list_descending(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 sort_list_descending(numbers: List[int]) -> List[int]:
"""
Sorts a list of numbers in descending order without modifying the original list.
Args:
numbers (List[int]): A list of numbers t... |
code_exercise_27k | 6,644 | Write a Python function to merge two lists into a single list while maintaining the order of elements from both lists. The function should handle lists of any data type, including mixed data types. The code should start with:
```python
from typing import List, Any
def merge_lists(list1: List[Any], list2: List[Any]) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def merge_lists(list1: List[Any], list2: List[Any]) -> List[Any]:
"""
Merge two lists into a single list while maintaining the order of elements from both lists.
Args:
list1 (List[Any])... |
code_exercise_27k | 6,645 | Write a Python function to remove duplicates from a sorted list while maintaining the order of the elements. The function should return a new list with all duplicate elements removed. The code should start with:
```python
from typing import List
def remove_duplicates_from_sorted_list(lst: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_from_sorted_list(lst: List[int]) -> List[int]:
"""
Remove duplicates from a sorted list while maintaining the order of the elements.
Args:
lst (List[int]): The sorted l... |
code_exercise_27k | 6,646 | Write a Python function to remove duplicates from a given list while maintaining the order of the elements. The function should return a new list with all unique elements in the order they first appeared in the original list. The code should start with:
```python
from typing import List
def remove_duplicates_ordered(l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_ordered(lst: List[int]) -> List[int]:
"""
Remove duplicates from a list while maintaining the order of the elements.
Args:
lst (List[int]): The list from which duplicat... |
code_exercise_27k | 6,651 | Write a Python function to find the maximum and minimum values in a given list of numbers. The function should handle the case where the list is empty by raising a `ValueError`. The code should start with:
```python
from typing import List, Tuple
def find_max_min(numbers: List[int]) -> Tuple[int, int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def find_max_min(numbers: List[int]) -> Tuple[int, int]:
"""
Find the maximum and minimum values in a given list of numbers.
Args:
numbers (List[int]): A list of integers.
Return... |
code_exercise_27k | 6,654 | Write a Python function to calculate the number of minutes between two given times in the format HH:MM. The function should handle cases where the end time is on the next day by considering the time difference across midnight. The code should start with:
```python
from datetime import datetime, timedelta
def calculate... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime, timedelta
def calculate_minutes_across_midnight(start_time: str, end_time: str) -> int:
"""
Calculates the number of minutes between two given times, considering cases where the end time is on the... |
code_exercise_27k | 6,657 | Write a Python function to convert a given date string in the format 'YYYY-MM-DD' to its corresponding date in words, following the format '1st January 2022'. The function should handle date validation and return the date in words.
The code should start with:
```python
def get_date_in_words(date: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def get_date_in_words(date: str) -> str:
"""
Converts a date string in the format 'YYYY-MM-DD' to its corresponding date in words, following the format '1st January 2022'.
Args:
date (str): A string representing the... |
code_exercise_27k | 6,660 | Write a Python function to remove all occurrences of a specific element from a given list. The function should return a new list with all occurrences of the specified element removed. The code should start with:
```python
from typing import List, Any
def remove_all_occurrences(lst: List[Any], element: Any) -> List[Any... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def remove_all_occurrences(lst: List[Any], element: Any) -> List[Any]:
"""
Remove all occurrences of a specific element from a list.
Args:
lst (List[Any]): The input list.
eleme... |
code_exercise_27k | 6,662 | Write a Python function to find the elements in a list that are not present in another list. The function should be efficient and handle cases where the lists contain duplicate elements. The code should start with:
```python
from typing import List
def find_unique_elements(list1: List[int], list2: List[int]) -> List[i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_unique_elements(list1: List[int], list2: List[int]) -> List[int]:
"""
Find the elements in list1 that are not present in list2.
Args:
list1 (List[int]): The first list of integers.
... |
code_exercise_27k | 6,663 | Write a Python function to remove elements at even positions from a given list. The function should return a new list containing only the elements that were originally at odd positions (i.e., indices 1, 3, 5, etc.). The function should handle lists of any length, including empty lists.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_elements_at_even_positions(lst: List[int]) -> List[int]:
"""
Removes elements at even positions from the given list and returns a new list with only the elements at odd positions.
Args:
... |
code_exercise_27k | 6,667 | Write a Python function to find the second largest number in a given list of integers. The function should handle lists with at least two elements and should return the second largest number. If the list contains fewer than two elements, the function should raise a `ValueError`. If all elements in the list are the same... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_second_largest(numbers: List[int]) -> int:
"""
Finds the second largest number in the given list of integers.
Args:
numbers (List[int]): A list of integers.
Returns:
in... |
code_exercise_27k | 6,674 | Write a Python function to find the previous occurrence of a specific weekday given a target date. The function should return the date of the previous occurrence of the target weekday. The code should start with:
```python
import datetime
def find_previous_weekday_from_date(target_weekday: int, target_date: datetime.d... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def find_previous_weekday_from_date(target_weekday: int, target_date: datetime.date) -> datetime.date:
"""
Find the previous occurrence of a specific weekday given a target date.
Args:
target_weekda... |
code_exercise_27k | 6,675 | Write a Python function to count the frequency of each value in a given dictionary. The function should return a new dictionary where the keys are the unique values from the input dictionary, and the values are the counts of how many times each value appears.
The code should start with:
```python
from typing import Di... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_value_frequencies(dictionary: Dict[int, str]) -> Dict[str, int]:
"""
Count the frequency of each value in a given dictionary.
Args:
dictionary (Dict[int, str]): The input dictionar... |
code_exercise_27k | 6,677 | Write a Python function to find the most frequent element in a given list. If there are multiple elements with the same highest frequency, the function should return the one that appears first in the list. If the list is empty, the function should return `None`.
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, Optional
def find_most_frequent_element(lst: List[int]) -> Optional[int]:
"""
Find the most frequent element in a given list.
Args:
lst (List[int]): The list of integers from which to find ... |
code_exercise_27k | 6,679 | Write a Python function to rotate the elements of a list to the right by a given number of positions. The function should handle cases where the number of positions to rotate exceeds the length of the list. The code should start with:
```python
from typing import List
def rotate_list_right(lst: List[int], positions: i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def rotate_list_right(lst: List[int], positions: int) -> List[int]:
"""
Rotates the elements of a list to the right by the specified number of positions.
Args:
lst (List[int]): The input lis... |
code_exercise_27k | 6,681 | Write a Python function to find the second smallest value in a given dictionary. The function should handle dictionaries with at least two values and ensure that the second smallest value is distinct from the smallest value. If the dictionary does not contain at least two distinct values, the function should raise a `V... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def find_second_smallest_value(dictionary: Dict[str, int]) -> int:
"""
Find the second smallest value in a dictionary.
Args:
dictionary (Dict[str, int]): The dictionary to search in.
Re... |
code_exercise_27k | 6,684 | Write a Python function to calculate the sum of all positive numbers in a given list. The function should handle both integers and floating-point numbers. The code should start with:
```python
from typing import List
def sum_of_positives(numbers: List[float]) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_positives(numbers: List[float]) -> float:
"""
Calculates the sum of all positive numbers in the given list.
Args:
numbers (List[float]): A list of numbers (integers or floating-po... |
code_exercise_27k | 6,686 | Write a Python function to partition a list into two lists based on a given condition. The function should take a list and a condition function as input and return a tuple containing two lists. The first list should contain items from the input list for which the condition is True, and the second list should contain th... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable, Tuple
def partition_list(lst: List, condition: Callable[[any], bool]) -> Tuple[List, List]:
"""
Partition a list into two lists based on a condition.
Args:
lst (list): The list to... |
code_exercise_27k | 6,689 | Write a Python function to calculate the product of all negative numbers in a given list. If the list does not contain any negative numbers, the function should return `None`. The function should handle lists of integers and floats. The code should start with:
```python
from typing import List, Optional
def product_of... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def product_of_negatives(numbers: List[float]) -> Optional[float]:
"""
Calculate the product of all negative numbers in a given list.
Args:
numbers (List[float]): A list of numbers... |
code_exercise_27k | 6,691 | Write a Python function to split a given list into multiple sublists of equal sizes. If the size of the sublists does not evenly divide the length of the list, the last sublist should contain the remaining elements. The function should handle cases where the list is empty or the size is less than or equal to 0 by raisi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def split_list_into_sublists(lst: List[int], size: int) -> List[List[int]]:
"""
Split a list into multiple sublists of equal sizes.
Args:
lst (List[int]): The original list to be split.
... |
code_exercise_27k | 6,692 | Write a Python function to multiply all the values in a given dictionary. The dictionary contains numeric values (integers or floats). The function should return the product of all the values. If the dictionary is empty, the function should return 1.
The code should start with:
```python
def multiply_values_in_dict(di... | Here is the Python code to solve the given problem in the markdown block:
```python
def multiply_values_in_dict(dictionary: dict) -> int or float:
"""
Multiplies all the values in a given dictionary.
Args:
dictionary (dict): The dictionary containing numeric values.
Returns:
int or flo... |
code_exercise_27k | 6,693 | Write a Python function to remove all zeros from a given list of integers. The function should return a new list that contains all the non-zero elements from the original list, maintaining their original order. The code should start with:
```python
from typing import List
def remove_zeros(lst: List[int]) -> List[int]:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_zeros(lst: List[int]) -> List[int]:
"""
Remove all zeros from a given list of integers.
Args:
lst (List[int]): A list containing integers and/or zeros.
Returns:
List[... |
code_exercise_27k | 6,696 | Write a Python function to find the common items between two dictionaries, including both common keys and values. The function should return a new dictionary containing only the common items. The code should start with:
```python
from typing import Dict
def find_common_items(dict1: Dict, dict2: Dict) -> Dict:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def find_common_items(dict1: Dict, dict2: Dict) -> Dict:
"""
Find common items between two dictionaries, including both common keys and values.
Args:
dict1 (Dict): The first dictionary.
... |
code_exercise_27k | 6,697 | Write a Python function to calculate the difference between adjacent elements in a given list of numbers. The function should return a new list containing the differences between each pair of adjacent elements. If the input list has fewer than two elements, the function should return an empty list.
The code should sta... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def calculate_adjacent_differences(lst: List[int]) -> List[int]:
"""
Calculate the difference between adjacent elements in a list.
Args:
lst (List[int]): A list of numbers.
Returns:
... |
code_exercise_27k | 6,700 | Write a Python function to find the maximum subarray sum in a given list of integers using Kadane's Algorithm. The function should return the maximum sum of a contiguous subarray within the given list. The code should start with:
```python
from typing import List
def max_subarray_sum(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def max_subarray_sum(arr: List[int]) -> int:
"""
Finds the maximum subarray sum in a given list using Kadane's Algorithm.
Args:
arr (List[int]): A list of integers.
Returns:
int... |
code_exercise_27k | 6,702 | 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 such number exists. The code should start with:
```python
from typing import List, Union
def find_largest_smaller_number(lst: List[Union[int, float]], target: Union[int, float]) -> U... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def find_largest_smaller_number(lst: List[Union[int, float]], target: Union[int, float]) -> Union[int, float, None]:
"""
Find the largest number in a list that is smaller than a given value.
... |
code_exercise_27k | 6,706 | Write a Python function to remove duplicates from a given list while preserving the order of the elements. The function should take a list as input and return a new list with all duplicate elements removed, maintaining the first occurrence of each element in the original list.
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 remove_duplicates_preserve_order(lst: List[int]) -> List[int]:
"""
Removes duplicates from a list while preserving the order of the elements.
Args:
lst (List[int]): The list from which d... |
code_exercise_27k | 6,708 | Write a Python function to remove the first occurrence of a specified element from a given list. If the element is not found in the list, the function should return the original list without any modifications. The function should handle lists of any type of elements, including integers, strings, and other objects. The ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def remove_first_occurrence(lst: List[Any], element: Any) -> List[Any]:
"""
Remove the first occurrence of a specified element from a given list.
If the element is not found in the list, the or... |
code_exercise_27k | 6,710 | Write a Python function to check if two dictionaries are disjoint (have no common keys). The function should return `True` if the dictionaries are disjoint, and `False` otherwise. The code should start with:
```python
def are_disjoint(dict1: dict, dict2: dict) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def are_disjoint(dict1: dict, dict2: dict) -> bool:
"""
Check if two dictionaries are disjoint (have no common keys).
Args:
dict1 (dict): The first dictionary.
dict2 (dict): The second dictionary.
Retur... |
code_exercise_27k | 6,712 | Write a Python function to remove all occurrences of a specified element from a given list. The function should return a new list with all occurrences of the specified element removed. The original list should not be modified. The code should start with:
```python
from typing import List
def remove_element(lst: List, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_element(lst: List, value) -> List:
"""
Removes all occurrences of a specified value from a given list.
Args:
lst (List): The list from which to remove the element.
value: ... |
code_exercise_27k | 6,713 | Write a Python function to remove elements at even indices from a given list. The function should return a new list containing only the elements from the original list that were at odd indices. The function should handle lists of any length, including empty lists.
The code should start with:
```python
from typing impo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_elements_at_even_indices(lst: List[int]) -> List[int]:
"""
Remove elements at even indices from a given list.
Args:
lst (List[int]): The input list from which elements at even ind... |
code_exercise_27k | 6,714 | Write a Python function to merge two dictionaries while concatenating the values of common keys. The function should handle dictionaries with string values only. The code should start with:
```python
from typing import Dict
def merge_dicts_concat_values(dict1: Dict[str, str], dict2: 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 merge_dicts_concat_values(dict1: Dict[str, str], dict2: Dict[str, str]) -> Dict[str, str]:
"""
Merge two dictionaries while concatenating the values of common keys.
Args:
dict1 (Dict[str... |
code_exercise_27k | 6,716 | Write a Python function to remove duplicate elements from a given list while preserving the order of the elements. The function should return a new list with the unique elements in the same order as they first appeared in the input list. The code should start with:
```python
from typing import List
def remove_duplicat... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_duplicates_preserve_order(input_list: List[int]) -> List[int]:
"""
Removes duplicate elements from a list while preserving the order of elements.
Args:
input_list (List[int]): The... |
code_exercise_27k | 6,717 | Write a Python function to remove elements at odd indices from a given list. The function should return a new list containing only the elements at even indices. The code should start with:
```python
from typing import List
def remove_odd_indices(lst: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_odd_indices(lst: List[int]) -> List[int]:
"""
Removes elements at odd indices from a given list and returns a new list with only the elements at even indices.
Args:
lst (List[int]... |
code_exercise_27k | 6,719 | Write a Python function to calculate the difference between two given dates in days, hours, minutes, and seconds. The function should accept two date strings in the format `"YYYY-MM-DD HH:MM:SS"` and return a dictionary containing the time difference in days, hours, minutes, and seconds.
The code should start with:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def get_time_diff(start_date: str, end_date: str) -> dict:
"""
Calculates the difference between two given dates in days, hours, minutes, and seconds.
Args:
start_date (str): The start... |
code_exercise_27k | 6,721 | Write a Python function to extract the unique elements from a given list while preserving their original order. The function should return a new list containing only the first occurrence of each element from the original list.
The code should start with:
```python
from typing import List
def extract_unique_elements_p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def extract_unique_elements_preserve_order(lst: List[int]) -> List[int]:
"""
Extracts the unique elements from a list while preserving their original order.
Args:
lst (List[int]): The input ... |
code_exercise_27k | 6,726 | Write a Python function to find the top n elements in a given dictionary based on their values. The function should return a list of tuples, where each tuple contains a key-value pair from the dictionary, sorted in descending order by value. If n is greater than the number of elements in the dictionary, the function sh... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def find_top_n_elements(dictionary: Dict[str, int], n: int) -> List[Tuple[str, int]]:
"""
Find the top n elements in a dictionary based on their values.
Args:
dictionary (Dict[s... |
code_exercise_27k | 6,727 | Write a Python function to remove elements from a given list that are less than a specified value. The function should return a new list containing only the elements that are greater than or equal to the specified value. The code should start with:
```python
from typing import List
def remove_elements_less_than(lst: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_elements_less_than(lst: List[int], value: int) -> List[int]:
"""
Removes elements from a list that are less than a given value.
Args:
lst (List[int]): The list from which elements... |
code_exercise_27k | 6,729 | Write a Python function to split a list into two parts, where each part contains equal numbers of positive and negative elements. If the list contains an unequal number of positive and negative elements, the function should return the smaller of the two lists, ensuring both lists have the same length.
The code should ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def split_list_equal_pos_neg(lst: List[int]) -> Tuple[List[int], List[int]]:
"""
Split a list into two parts, where each part contains equal numbers of positive and negative elements.
Args:
... |
code_exercise_27k | 6,730 | Write a Python function to calculate the time it takes for a train to travel a given distance at a constant speed. The function should handle both positive and zero speeds, and return `None` for zero speed. The code should start with:
```python
def calculate_travel_time(distance: float, speed: float) -> float:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def calculate_travel_time(distance: float, speed: float) -> float:
"""
Calculate the time it takes for a train to travel a given distance at a constant speed.
Args:
distance (float): The distance traveled by the tra... |
code_exercise_27k | 6,733 | Write a Python function to manage a dictionary that stores the frequency of words in a given text. The function should be able to:
1. Add words from a text to the dictionary and update their frequencies.
2. Retrieve the frequency of a specific word.
3. Check if a word exists in the dictionary.
4. Remove a word from the... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Union
def word_frequency_manager(text: str, word_dict: Dict[str, int] = None) -> Dict[str, int]:
"""
Manages the frequency of words in a given text using a dictionary.
Args:
text (str): The... |
code_exercise_27k | 6,734 | Write a Python function to remove elements from a given list based on a specified condition. The condition is defined by a boolean function that takes an element as input and returns `True` if the element should be removed, and `False` otherwise. The function should return the modified list with the elements removed.
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable
def remove_elements(lst: List, condition: Callable[[any], bool]) -> List:
"""
Remove elements from the given list based on the specified condition.
Args:
lst (List): The list from ... |
code_exercise_27k | 6,735 | Write a Python function to find the elements in a list that have an even index. The function should return a new list containing only the elements at even indices from the input list. The code should start with:
```python
from typing import List
def get_elements_with_even_index(lst: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_elements_with_even_index(lst: List[int]) -> List[int]:
"""
Finds the elements in a list that have an even index.
Args:
lst (List[int]): The input list from which to extract elements ... |
code_exercise_27k | 6,739 | Write a Python function to find the elements in a list that have an odd index. The function should return a new list containing only the elements at odd indices. The code should start with:
```python
from typing import List
def find_elements_with_odd_index(lst: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_elements_with_odd_index(lst: List[int]) -> List[int]:
"""
Finds the elements in a list that have an odd index.
Args:
lst (List[int]): The input list from which to extract elements a... |
code_exercise_27k | 6,741 | Write a Python function to safely access a nested dictionary value using a list of keys. If any key in the list does not exist in the corresponding dictionary level, the function should return `None`. The function should handle dictionaries of arbitrary depth.
The code should start with:
```python
from typing import A... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any, List, Optional
def get_nested_value(dictionary: dict, keys: List[Any]) -> Optional[Any]:
"""
Safely access a nested dictionary value using a list of keys.
Args:
dictionary (dict): The dictio... |
code_exercise_27k | 6,742 | Write a Python function to remove all whitespace characters from each string in a given list of strings. The function should return a new list with all the whitespace characters removed from each string. The code should start with:
```python
from typing import List
def remove_whitespace_from_list(elements: List[str]) ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_whitespace_from_list(elements: List[str]) -> List[str]:
"""
Removes all whitespace characters from each string in a given list of strings.
Args:
elements (List[str]): A list of st... |
code_exercise_27k | 6,743 | Write a Python function to find the elements in a list whose indices are divisible by a given integer `k`. The function should return a new list containing these elements. The code should start with:
```python
from typing import List
def get_elements_with_index_divisible_by_k(lst: List[int], k: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_elements_with_index_divisible_by_k(lst: List[int], k: int) -> List[int]:
"""
Find the elements in a list whose indices are divisible by a given integer k.
Args:
lst (List[int]): A li... |
code_exercise_27k | 6,744 | Write a Python function to update the value associated with a specific key in a dictionary. If the key does not exist in the dictionary, the function should add the key with the specified value. The function should handle both cases where the key is present and where it is not.
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 Dict
def update_or_add_key(dictionary: Dict[str, any], key: str, value: any) -> Dict[str, any]:
"""
Updates the value associated with the specified key in the dictionary.
If the key does not exist, it add... |
code_exercise_27k | 6,748 | Write a Python function to find the elements in a given list that have an index divisible by a specified divisor. The function should take two parameters: the list and the divisor. The function should return a new list containing the elements with an index divisible by the specified divisor.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_elements_with_index_divisible_by(lst: List[int], divisor: int) -> List[int]:
"""
Finds the elements in a given list that have an index divisible by the specified divisor.
Args:
lst ... |
code_exercise_27k | 6,749 | Write a Python function to remove elements from a given list that start with a specific substring. The function should return the modified list with the specified elements removed. The code should start with:
```python
from typing import List
def remove_elements_starting_with(lst: List[str], substring: str) -> List[st... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_elements_starting_with(lst: List[str], substring: str) -> List[str]:
"""
Remove elements from the given list that start with the specified substring.
Args:
lst (List[str]): The in... |
code_exercise_27k | 6,750 | Write a Python function to check if a given key exists in a dictionary and return the corresponding value if it exists. If the key does not exist, return a default value provided by the user. The function should handle cases where the dictionary or the key is `None`.
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 Any, Optional
def get_value_or_default(dictionary: Optional[dict], key: Any, default: Any) -> Any:
"""
Check if the given key exists in the dictionary and return its value.
If the key does not exist, retu... |
code_exercise_27k | 6,753 | Write a Python function to find the elements in a list that have an index divisible by a given divisor. The function should return a new list containing these elements. The code should start with:
```python
from typing import List
def find_elements_with_index_divisible_by(my_list: List[int], divisor: int) -> List[int]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_elements_with_index_divisible_by(my_list: List[int], divisor: int) -> List[int]:
"""
Find the elements in a list that have an index divisible by a given divisor.
Args:
my_list (List... |
code_exercise_27k | 6,761 | Write a Python function to find the elements in a list that have an index divisible by a given integer `k`. The function should return a list of these elements. The code should start with:
```python
from typing import List
def find_elements_with_index_divisible_by_k(lst: List[int], k: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_elements_with_index_divisible_by_k(lst: List[int], k: int) -> List[int]:
"""
Find the elements in a list that have an index divisible by a given integer k.
Args:
lst (List[int]): Th... |
code_exercise_27k | 6,764 | Write a Python function to create and return a dictionary representing a book with specified key-value pairs. The dictionary should include the keys "title", "author", and "year", each with corresponding values. The function should also handle optional parameters for additional book details such as "genre" and "publish... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Optional
def create_book_dictionary(title: str, author: str, year: int, genre: Optional[str] = None, publisher: Optional[str] = None) -> dict:
"""
Creates and returns a dictionary representing a book with spe... |
code_exercise_27k | 6,767 | Write a Python function to find the elements in a list that have an index divisible by a given divisor. The function should take a list and an integer divisor as input and return a new list containing the elements from the input list that have an index divisible by the given divisor.
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_elements_with_index_divisible_by(lst: List[int], divisor: int) -> List[int]:
"""
Find the elements in a list that have an index divisible by a given divisor.
Args:
lst (List[int]): ... |
code_exercise_27k | 6,768 | Write a Python function to merge two dictionaries into a new dictionary. If there are overlapping keys, the values from the second dictionary should overwrite the values from the first dictionary. The function should handle cases where the input dictionaries are empty or contain overlapping keys. The code should start ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def merge_dictionaries(dict1: Dict, dict2: Dict) -> Dict:
"""
Merge two dictionaries into a new dictionary. If there are overlapping keys,
the values from the second dictionary will overwrite the val... |
code_exercise_27k | 6,770 | Write a Python function to find and return the elements in a given list whose indices are divisible by a specified divisor. The function should handle cases where the divisor is zero, returning an empty list in such cases. The function should also handle cases where the list is empty.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def get_elements_by_index_divisible_by(lst: List[int], divisor: int) -> List[int]:
"""
Returns the elements in the given list whose indices are divisible by the specified divisor.
Args:
lst ... |
code_exercise_27k | 6,771 | Write a Python function to filter elements from a list based on multiple conditions. The function should return a new list containing only the elements that satisfy all the given conditions. Each condition is a lambda function that takes an element as input and returns a boolean value.
The code should start with:
```p... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Callable
def filter_elements(lst: List, conditions: List[Callable[[any], bool]]) -> List:
"""
Filters elements from a list based on multiple conditions.
Args:
lst (list): The input list fro... |
code_exercise_27k | 6,774 | Write a Python function to find the elements in a list that have an index divisible by a given divisor. The function should take a list of elements and an integer divisor as input and return a list of elements whose indices are divisible by the divisor. 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 find_elements_with_divisible_index(elements: List, divisor: int) -> List:
"""
Find the elements in a list that have an index divisible by a given divisor.
Args:
elements (List): A list o... |
code_exercise_27k | 6,775 | Write a Python function to check if a given key exists in a dictionary and return the corresponding value if the key exists, otherwise return a default value. The function should handle cases where the dictionary is empty or the key is not present.
The code should start with:
```python
from typing import Any, Dict, Op... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any, Dict, Optional
def get_value_or_default(dictionary: Dict[str, Any], key: str, default: Optional[Any] = None) -> Optional[Any]:
"""
Check if a given key exists in a dictionary and return the corresponding... |
code_exercise_27k | 6,777 | Write a Python function to remove elements from a given list that have an even index. The function should return a new list containing only the elements from the original list that were located at odd indices. The code should start with:
```python
from typing import List
def remove_even_index_elements(lst: List[int]) ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_even_index_elements(lst: List[int]) -> List[int]:
"""
Remove the elements in a list that have an even index and return a new list with only the elements at odd indices.
Args:
lst ... |
code_exercise_27k | 6,779 | Write a Python function to remove duplicates from a given list while preserving the order of the elements. The function should return a new list with all unique elements in the order they first appeared in the original list. The code should start with:
```python
from typing import List
def remove_duplicates_preserve_o... | 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 duplicates from a list while preserving the order of elements.
Args:
lst (List[int]): The input list with potent... |
code_exercise_27k | 6,781 | Write a Python function to remove elements from a list that have odd indices. The function should return a new list containing only the elements from the original list that have even indices. The code should start with:
```python
from typing import List
def remove_odd_index_elements(lst: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_odd_index_elements(lst: List[int]) -> List[int]:
"""
Remove the elements in a list that have an odd index.
Args:
lst (List[int]): A list of integers from which to remove elements ... |
code_exercise_27k | 6,783 | Write a Python function to remove the first 'N' elements from a given list. The function should handle cases where 'N' is greater than the length of the list by returning an empty list. The function should also raise a `ValueError` if 'N' is a negative integer.
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 remove_first_elements(lst: List[int], n: int) -> List[int]:
"""
Remove the first 'N' elements from a given list.
Args:
lst (List[int]): The input list from which elements are to be remov... |
code_exercise_27k | 6,787 | Write a Python function to remove the first 'N' elements from a given list. The function should handle cases where `N` is greater than the length of the list by returning an empty list. The function should also handle cases where `N` is negative by raising a `ValueError`. 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 List
def remove_first_elements(lst: List, N: int) -> List:
"""
Remove the first 'N' elements from a given list.
Args:
lst (List): The original list from which elements are to be removed.
... |
code_exercise_27k | 6,793 | Write a Python function to determine if a given date is a weekend. The function should accept either a string in "YYYY-MM-DD" format or a `datetime.date` object as input and return `True` if the date is a weekend (Saturday or Sunday) and `False` otherwise. The function should raise a `ValueError` if the input is not in... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def is_weekend(date):
"""
Determine if a given date is a weekend.
Parameters:
date (str or datetime.date): The date to check. Can be a string in "YYYY-MM-DD" format or a datetime.date object.
Retur... |
code_exercise_27k | 6,795 | Write a Python function to remove consecutive duplicate elements from a given list. The function should iterate through the list and remove any element that is the same as the previous element, ensuring that only the first occurrence of each consecutive duplicate is retained. The function should handle lists of any len... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_consecutive_duplicates(lst: List[int]) -> List[int]:
"""
Remove consecutive duplicate elements from a given list.
Args:
lst (List[int]): The input list from which to remove consec... |
code_exercise_27k | 6,799 | Write a Python function to update the value associated with a specific key in a dictionary. The function should take a dictionary and a key-value pair as input and update the dictionary with the new value for the specified key. If the key does not exist in the dictionary, the function should add the key-value pair to t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def update_dictionary(dictionary: Dict[str, Any], key: str, value: Any) -> Dict[str, Any]:
"""
Updates the value associated with a specific key in the given dictionary.
If the key does not exist... |
code_exercise_27k | 6,802 | Write a Python function to remove a specified key-value pair from a given dictionary. If the key does not exist in the dictionary, the function should return the original dictionary without raising any exceptions. The function should start with:
```python
from typing import Dict
def remove_key(dictionary: Dict, key: s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def remove_key(dictionary: Dict, key: str) -> Dict:
"""
Remove a specified key-value pair from the given dictionary.
Args:
dictionary (dict): The dictionary from which to remove the key-valu... |
code_exercise_27k | 6,803 | Write a Python function to remove elements from a list that have an index divisible by a given integer `k`. The function should take a list and an integer `k` as input and return the updated list with the specified elements removed. The code should start with:
```python
from typing import List
def remove_elements_at_i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_elements_at_indices_divisible_by_k(lst: List[int], k: int) -> List[int]:
"""
Remove elements from a list that have an index divisible by a given integer `k`.
Args:
lst (List[int])... |
code_exercise_27k | 6,804 | Write a Python function to remove elements from a given list based on specific indices. The function should handle input validation and ensure that the indices provided are within the valid range of the list. If any index is out of range, the function should raise an `IndexError`. If the input types are not as expected... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_elements_by_index(lst: List[int], indices: List[int]) -> List[int]:
"""
Remove elements from a list based on specific indices.
Args:
lst (List[int]): The original list.
in... |
code_exercise_27k | 6,805 | Write a Python function to search for a contact by name in a given dictionary of contacts. The function should return the phone number of the contact if found, otherwise return `None`. The dictionary structure is as follows: each key is a string representing a person's identifier (e.g., "person1"), and each value is a ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Optional
def find_contact_by_name(contacts: Dict[str, Dict[str, str]], name: str) -> Optional[str]:
"""
Searches for a contact by name in a given dictionary of contacts and returns the phone number if f... |
code_exercise_27k | 6,813 | Write a Python function to remove elements from a list that start with a specific character and are adjacent to it. The function should iterate through the list and remove any element that starts with the specified character and is immediately followed by another element that also starts with the same character. The fu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_adjacent_elements(lst: List[str], start_char: str) -> List[str]:
"""
Remove elements from a list that start with a specific character and are adjacent to it.
Args:
lst (List[str])... |
code_exercise_27k | 6,814 | Write a Python function to update the phone number of a specific person in a given dictionary of contacts. The function should take three parameters: a dictionary containing contact information, the name of the person whose phone number needs to be updated, and the new phone number. The function should return the updat... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def update_phone_number(contacts: Dict[str, Dict[str, str]], person: str, new_number: str) -> Dict[str, Dict[str, str]]:
"""
Update the phone number of a specific person in the contacts dictionary.
... |
code_exercise_27k | 6,817 | Write a Python function to remove elements from a list that end with a specific character and are adjacent to it. The function should iterate through the list and remove both the current element and the next element if they both end with the specified suffix. If only the current element ends with the suffix, it should ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_adjacent_with_suffix(lst: List[str], suffix: str) -> List[str]:
"""
Remove elements from the input list that end with a specific character and are adjacent to it.
Args:
lst (List[... |
code_exercise_27k | 6,819 | Write a Python function to find all the sublists of a given list. A sublist is defined as a contiguous sequence of elements within the list. The function should return a list of all possible sublists.
The code should start with:
```python
from typing import List
def find_all_sublists(lst: List[int]) -> List[List[int]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_all_sublists(lst: List[int]) -> List[List[int]]:
"""
Finds all the sublists of a given list.
Args:
lst (List[int]): The input list.
Returns:
List[List[int]]: A list of ... |
code_exercise_27k | 6,828 | Write a Python function to calculate the number of seconds between two given timestamps. The timestamps are provided as strings in the format 'YYYY-MM-DD HH:MM:SS'. The function should handle the parsing of the timestamps and return the absolute difference in seconds between the two timestamps.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def get_seconds_between_timestamps(timestamp1: str, timestamp2: str) -> int:
"""
Calculate the absolute number of seconds between two given timestamps.
Args:
timestamp1 (str): The firs... |
code_exercise_27k | 6,830 | Write a Python function to update the quantity of a product in a sales dictionary. If the product does not exist in the dictionary, the function should raise a `KeyError`. The function should return the updated sales dictionary.
The code should start with:
```python
def update_product_quantity(sales: dict, product_nam... | Here is the Python code to solve the given problem in the markdown block:
```python
def update_product_quantity(sales: dict, product_name: str, quantity: int) -> dict:
"""
Update the quantity of a product in the sales dictionary.
Args:
sales (dict): A dictionary representing the sales information.
... |
code_exercise_27k | 6,833 | Write a Python function to remove a specific key-value pair from a dictionary. If the key does not exist in the dictionary, the function should return the dictionary unchanged. The function should handle any type of dictionary and key.
The code should start with:
```python
def remove_key_value(dictionary: dict, key) -... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_key_value(dictionary: dict, key) -> dict:
"""
Remove a specific key-value pair from a dictionary. If the key does not exist, the dictionary remains unchanged.
Args:
dictionary (dict): The dictionary from ... |
code_exercise_27k | 6,841 | Write a Python function to remove consecutive duplicate elements from a given list. The function should return a new list where each element appears only once in the sequence, even if it was originally repeated consecutively. The code should start with:
```python
from typing import List
def remove_consecutive_duplicat... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_consecutive_duplicates(lst: List[int]) -> List[int]:
"""
Remove consecutive duplicate elements from the given list.
Args:
lst (List[int]): The input list from which to remove cons... |
code_exercise_27k | 6,844 | Write a Python function to calculate the number of business days (excluding weekends) between two given dates. The function should handle the following:
1. Accept two `datetime.date` objects as input.
2. Ensure the start date is before the end date.
3. Count only weekdays (Monday to Friday) and exclude weekends (Saturd... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def get_business_days(start_date: datetime.date, end_date: datetime.date) -> int:
"""
Calculate the number of business days (excluding weekends) between two given dates.
Args:
start_date (datetime.d... |
code_exercise_27k | 6,852 | Write a Python function to find all the prime numbers in a given list of numbers. The function should return a list of prime numbers found in the input list. The function should be efficient and handle edge cases such as an empty list or a list containing non-prime numbers.
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
def is_prime(num: int) -> bool:
"""Check if a number is prime.
Args:
num (int): The number to check for primality.
Returns:
bool: True if the number is prime, False otherwis... |
code_exercise_27k | 6,854 | Write a Python function to remove non-alphabetic characters from a given list of strings. The function should return a new list containing only the elements that consist entirely of alphabetic characters. The code should start with:
```python
from typing import List
def remove_non_alphabetic_elements(lst: List[str]) -... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_non_alphabetic_elements(lst: List[str]) -> List[str]:
"""
Removes non-alphabetic elements from a list of strings.
Args:
lst (List[str]): The list of strings from which non-alphabe... |
code_exercise_27k | 6,856 | Write a Python function to remove elements from a given list that do not contain any numeric characters. The function should return a new list containing only the elements that have at least one numeric character. The code should start with:
```python
from typing import List
def remove_non_numeric_elements(lst: List[s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_non_numeric_elements(lst: List[str]) -> List[str]:
"""
Removes elements from the given list that do not contain any numeric characters.
Args:
lst (List[str]): The list from which ... |
code_exercise_27k | 6,863 | Write a Python function to remove elements from a given list that are unique to that list. An element is considered unique if it appears only once in the list. The function should return a new list containing only the non-unique elements.
The code should start with:
```python
from typing import List
def remove_unique... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_unique_elements(lst: List[int]) -> List[int]:
"""
Remove elements from a list that are unique to that list.
Args:
lst (List[int]): The input list from which unique elements are to... |
code_exercise_27k | 6,864 | Write a Python function to remove a specified key-value pair from a given dictionary. If the key does not exist in the dictionary, the function should return the dictionary unchanged. The function should start with:
```python
def remove_key_value_pair(dictionary: dict, key) -> dict:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def remove_key_value_pair(dictionary: dict, key) -> dict:
"""
Removes a specified key-value pair from the given dictionary.
Args:
dictionary (dict): The dictionary from which to remove the key-value pair.
ke... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.