source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
code_exercise_27k | 7,499 | Write a Python function to sort a list of integers in ascending order, while moving all numbers divisible by 3 to the front of the list. The function should maintain the relative order of the numbers not divisible by 3. The code should start with:
```python
from typing import List
def sort_list_with_divisible_by_3_at_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_list_with_divisible_by_3_at_front(numbers: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order, while moving all numbers divisible by 3 to the front.
Args:
numb... |
code_exercise_27k | 7,500 | Write a Python function to find the indexes of a specific value in a dictionary value. The dictionary values are lists of integers. The function should return a list of tuples where each tuple contains a key from the dictionary and the index of the value in the corresponding list.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Tuple
def find_value_indexes(dictionary: Dict[str, List[int]], value: int) -> List[Tuple[str, int]]:
"""
Find the indexes of a specific value in the lists of integers within a dictionary.
Arg... |
code_exercise_27k | 7,506 | Write a Python function to sort a list of strings in alphabetical order, ignoring all non-alphanumeric characters, case sensitivity, and leading/trailing whitespace. The function should return a new list of sorted strings.
The code should start with:
```python
from typing import List
import re
def sort_strings_ignore... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import re
def sort_strings_ignore_non_alphanumeric(strings: List[str]) -> List[str]:
"""
Sorts a list of strings in alphabetical order, ignoring non-alphanumeric characters,
case sensitivity, and lea... |
code_exercise_27k | 7,510 | Write a Python function to reverse the keys and values in a dictionary while keeping the duplicated values intact. The function should return a new dictionary where each value from the original dictionary becomes a key, and the corresponding keys (if there are duplicates) are stored in a list.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Union
def reverse_dict_with_duplicates(dictionary: Dict[str, int]) -> Dict[int, List[str]]:
"""
Reverses the keys and values of a dictionary while keeping the duplicated values intact.
Args:
... |
code_exercise_27k | 7,524 | Write a Python function to calculate the cumulative sum of the values in a given dictionary. The function should return a new dictionary where each key maps to the cumulative sum of the values up to that key in the original dictionary. The original dictionary contains numeric values.
The code should start with:
```pyt... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def calculate_cumulative_sum(dictionary: Dict[str, int]) -> Dict[str, int]:
"""
Calculates the cumulative sum of the values in a dictionary.
Args:
dictionary (Dict[str, int]): A dictionary w... |
code_exercise_27k | 7,525 | Write a Python function to create a deep copy of a nested list. A deep copy means that any changes to the original list or its nested elements should not affect the copied list, and vice versa. The function should handle lists containing other lists, dictionaries, and other mutable objects.
The code should start with:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any
import copy
def deep_copy_list(input_list: list) -> list:
"""
Create a deep copy of a nested list.
This function takes an input list, which may contain other lists, dictionaries,
or other mutable... |
code_exercise_27k | 7,526 | Write a Python function to clone a list using the slicing method. The function should create a new list that is a copy of the original list, ensuring that changes to the cloned list do not affect the original list. The code should start with:
```python
from typing import List
def clone_list(lst: List) -> List:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def clone_list(lst: List) -> List:
"""
Clones a given list using the slicing method.
Args:
lst (List): The list to be cloned.
Returns:
List: A new list that is a clone of the or... |
code_exercise_27k | 7,527 | Write a Python function to find the minimum and maximum values in a dictionary without using built-in functions like `min()` and `max()`. The function should return a tuple containing the minimum and maximum values. If the dictionary is empty, the function should raise a `ValueError`.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_min_max_values(dictionary: dict) -> tuple:
"""
Finds the minimum and maximum values in a dictionary without using built-in functions.
Args:
dictionary (dict): The dictionary to search for minimum and maximu... |
code_exercise_27k | 7,530 | Write a Python function to clone a list using the list() function. The function should create a new list that is a copy of the input list, ensuring that the original list and the cloned list are distinct objects in memory. The code should start with:
```python
from typing import List
def clone_list(lst: List) -> List:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def clone_list(lst: List) -> List:
"""
Clones a list using the list() function.
Args:
lst (List): The list to be cloned.
Returns:
List: A new list that is a clone of the input l... |
code_exercise_27k | 7,531 | Write a Python function to extract a portion of a dictionary based on the given keys. The function should return a new dictionary containing only the key-value pairs from the original dictionary that match the specified keys. If any of the specified keys are not present in the original dictionary, the function should r... | Here is the Python code to solve the given problem in the markdown block:
```python
def extract_dict_portion(dictionary: dict, keys: list) -> dict:
"""
Extracts a portion of a dictionary based on the given keys.
Args:
dictionary (dict): The dictionary from which to extract the portion.
keys... |
code_exercise_27k | 7,533 | Write a Python function to create a shallow copy of a given list. The function should return a new list that is a shallow copy of the input list. The shallow copy should have the same elements as the original list, but modifying the shallow copy should not affect the original list, except for nested objects (like lists... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def shallow_copy_list(lst: List) -> List:
"""
Create a shallow copy of a given list.
Args:
lst (List): The list to be copied.
Returns:
List: A new list that is a shallow copy of... |
code_exercise_27k | 7,535 | Write a Python function to create a dictionary from a list of strings, where the keys are the strings and the values are their lengths. The function should handle an empty list gracefully and return an empty dictionary in that case. The code should start with:
```python
from typing import List, Dict
def create_string_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_string_length_dict(strings: List[str]) -> Dict[str, int]:
"""
Create a dictionary from a list of strings, where the keys are the strings and the values are their lengths.
Args:
... |
code_exercise_27k | 7,536 | Write a Python function to create a deep copy of a given list. The function should handle lists containing nested lists and other mutable objects. The deep copy should ensure that any changes made to the copied list do not affect the original list. The code should start with:
```python
from typing import List, Any
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
import copy
def deep_copy_list(lst: List[Any]) -> List[Any]:
"""
Create a deep copy of a given list.
This function uses the `copy` module in Python to create a deep copy of the input list.
... |
code_exercise_27k | 7,545 | Write a Python function to sort a dictionary by its values in descending order. 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_dict_by_values_desc(dictionary: Dict[str, i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sort_dict_by_values_desc(dictionary: Dict[str, int]) -> Dict[str, int]:
"""
Sorts a dictionary by its values in descending order and returns the sorted dictionary.
Args:
dictionary (Dict... |
code_exercise_27k | 7,547 | Write a Python function to clone a list and remove all occurrences of a specific element from the cloned list. The function should return the modified cloned list. The code should start with:
```python
from typing import List, Any
def clone_and_remove_element(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 clone_and_remove_element(lst: List[Any], element: Any) -> List[Any]:
"""
Clones a list and removes all occurrences of a specific element from the cloned list.
Args:
lst (List[Any]):... |
code_exercise_27k | 7,549 | Write a Python function to merge two dictionaries, summing the values for common keys. The function should return a new dictionary that contains all keys from both dictionaries, with values summed for any common keys. The code should start with:
```python
from typing import Dict
def merge_and_sum_dictionaries(dict1: D... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def merge_and_sum_dictionaries(dict1: Dict[str, int], dict2: Dict[str, int]) -> Dict[str, int]:
"""
Merge two dictionaries, summing the values for common keys.
Args:
dict1 (Dict[str, int]): ... |
code_exercise_27k | 7,550 | Write a Python function to clone a list in reverse order. The function should create a new list that is a reversed copy of the original list. The original list should remain unchanged. The code should start with:
```python
from typing import List
def reverse_clone(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 reverse_clone(lst: List[int]) -> List[int]:
"""
Clones a list in reverse order.
Args:
lst (List[int]): The list to be cloned.
Returns:
List[int]: The cloned list in reverse ... |
code_exercise_27k | 7,552 | Write a Python function to clone a list in a randomized order. The function should create a shallow copy of the input list and then shuffle the elements of the copied list in a random order. The function should return the shuffled list. The code should start with:
```python
from typing import List
import random
def cl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def clone_and_shuffle_list(lst: List[int]) -> List[int]:
"""
Clones a list and returns a new list with its elements shuffled in a random order.
Args:
lst (List[int]): The list ... |
code_exercise_27k | 7,555 | Write a Python function to clone a nested list. The function should create a deep copy of the input nested list, ensuring that all nested structures are also cloned. The function should handle lists containing other lists, integers, strings, and other immutable types. The code should start with:
```python
from typing i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def clone_nested_list(nested_list: List[Any]) -> List[Any]:
"""
Clone a nested list.
This function takes a nested list as input and returns a new nested list that is a deep copy of the original... |
code_exercise_27k | 7,559 | Write a Python function to merge a list of dictionaries into a single dictionary, where common keys in the dictionaries are merged by summing their values. If a key appears in multiple dictionaries, its values should be summed. The function should handle dictionaries with integer values only.
The code should start wit... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def merge_dicts_with_sum(dicts: List[Dict[str, int]]) -> Dict[str, int]:
"""
Merge a list of dictionaries into a single dictionary, summing values for common keys.
Args:
dicts (List[Di... |
code_exercise_27k | 7,560 | Write a Python function to clone a list of dictionaries, ensuring that the cloned list is a deep copy of the original list. The function should handle nested dictionaries and lists within the dictionaries. The code should start with:
```python
from typing import List, Dict
import copy
def deep_clone_list_of_dicts(list... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
import copy
def deep_clone_list_of_dicts(list_of_dicts: List[Dict]) -> List[Dict]:
"""
Deep clone a list of dictionaries, including nested dictionaries and lists.
Args:
list_of_dicts (... |
code_exercise_27k | 7,563 | Write a Python function to create a copy of a list with specific elements filtered out. The function should take two arguments: the original list and a list of elements to be filtered out. The function should return a new list that contains all elements from the original list except those specified in the second list.
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_list(original_list: List, elements_to_filter: List) -> List:
"""
Create a copy of a list with specific elements filtered out.
Args:
original_list (List): The original list to filt... |
code_exercise_27k | 7,566 | Write a Python function to clone a list and multiply all elements by a given number. The function should return a new list with all elements from the original list multiplied by the specified multiplier. The original list should remain unchanged.
The code should start with:
```python
from typing import List, Union
de... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def clone_and_multiply(lst: List[Union[int, float]], multiplier: Union[int, float]) -> List[Union[int, float]]:
"""
Clone a list and multiply all elements by a given number.
Args:
lst... |
code_exercise_27k | 7,570 | Write a Python function to clone a list and add a suffix to each element. The function should take two parameters: the original list and the suffix to be added to each element. The function should return the cloned list with the suffix added to each element. The original list should remain unchanged.
The code should s... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def add_suffix_to_list_elements(lst: List[str], suffix: str) -> List[str]:
"""
Clone a list and add a suffix to each element.
Args:
lst (List[str]): The original list of strings.
suf... |
code_exercise_27k | 7,573 | Write a Python function to clone a list and concatenate it with another list. The function should ensure that the original list remains unchanged and that the concatenation is performed on a deep copy of the original list. The code should start with:
```python
from typing import List
def clone_and_concatenate_list(ori... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
from copy import deepcopy
def clone_and_concatenate_list(original_list: List, another_list: List) -> List:
"""
Clones a list and concatenates it with another list.
Args:
original_list (List)... |
code_exercise_27k | 7,577 | Write a Python function to clone a list of tuples. The function should create a deep copy of the list, ensuring that any changes to the original list do not affect the cloned list, and vice versa. The code should start with:
```python
from typing import List, Tuple
def clone_tuple_list(tuple_list: List[Tuple]) -> List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def clone_tuple_list(tuple_list: List[Tuple]) -> List[Tuple]:
"""
Clones a list of tuples, creating a deep copy of the list.
Args:
tuple_list (List[Tuple]): The list of tuples to be c... |
code_exercise_27k | 7,579 | Write a Python function to clone a list and sort it in descending order. The function should return a new list that is a clone of the original list, sorted in descending order. The code should start with:
```python
from typing import List
def clone_and_sort_list_descending(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 clone_and_sort_list_descending(lst: List[int]) -> List[int]:
"""
Clone a list and sort it in descending order.
Args:
lst (List[int]): The original list to clone.
Returns:
Li... |
code_exercise_27k | 7,582 | Write a Python function to clone a list and sort it in descending order. The function should return the cloned list sorted in descending order without modifying the original list. The code should start with:
```python
from typing import List
def clone_and_sort_descending(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 clone_and_sort_descending(lst: List[int]) -> List[int]:
"""
Clone a list and sort it in descending order.
Args:
lst (List[int]): The list to be cloned and sorted.
Returns:
L... |
code_exercise_27k | 7,590 | Write a Python function to calculate the sum of all values in a dictionary, ensuring that only numeric values are considered. If any non-numeric value is encountered, the function should raise a `ValueError`. The function should start with:
```python
from typing import Dict
def sum_dict_values_with_validation(dictiona... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import Dict
def sum_dict_values_with_validation(dictionary: Dict[str, int]) -> int:
"""
Calculate the sum of all numeric values in a dictionary.
Args:
dictionary (Dict[str, int]): A dictionary contain... |
code_exercise_27k | 7,594 | Write a Python function to multiply all the values in a given dictionary by a specified multiplier. The function should return a new dictionary with the same keys but with the values multiplied by the given number. The original dictionary should remain unchanged.
The code should start with:
```python
from typing impor... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Union
def multiply_dictionary_values(dictionary: Dict[str, Union[int, float]], multiplier: Union[int, float]) -> Dict[str, Union[int, float]]:
"""
Multiply all the values in a given dictionary by a spec... |
code_exercise_27k | 7,596 | Write a Python function to calculate the number of full decades between two given dates. The function should handle date strings in the format 'YYYY-MM-DD' and ensure that the start date is before the end date. If the start date is after the end date, the function should swap them. The function should return the number... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def calculate_full_decades(start_date: str, end_date: str) -> int:
"""
Calculates the number of full decades between two given dates.
Args:
start_date (str): The start date in the form... |
code_exercise_27k | 7,600 | Write a Python function to find the highest and lowest values in a given dictionary. The function should return a tuple containing the highest and lowest values. If the dictionary is empty, the function should raise a `ValueError`.
The code should start with:
```python
def find_high_low_values(dictionary: dict) -> tup... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_high_low_values(dictionary: dict) -> tuple:
"""
Find the highest and lowest values in a dictionary.
Args:
dictionary (dict): The input dictionary.
Returns:
tuple: A tuple containing two element... |
code_exercise_27k | 7,604 | Write a Python function to clone a given list and find the sum of all elements in the cloned list. The function should return both the cloned list and the sum of its elements. The code should start with:
```python
from typing import List, Tuple
def clone_and_sum_list(arr: List[int]) -> Tuple[List[int], int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def clone_and_sum_list(arr: List[int]) -> Tuple[List[int], int]:
"""
Clone a given list and find the sum of all elements in the cloned list.
Args:
arr (List[int]): The input list to b... |
code_exercise_27k | 7,607 | Write a Python function to create a dictionary from a given string, where each character (excluding whitespace) is a key and the value is the count of occurrences of that character in the string. The function should be case-insensitive, meaning 'A' and 'a' should be treated as the same character.
The code should start... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def create_char_count_dict(string: str) -> Dict[str, int]:
"""
Creates a dictionary from a given string where each character (excluding whitespace) is a key,
and the value is the count of occurrences... |
code_exercise_27k | 7,613 | Write a Python function to clone a list and convert all elements to uppercase. The function should create a new list with the same elements as the input list, but with each element converted to uppercase. The input list may contain strings of varying lengths and may include empty strings. The function should handle lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def clone_and_convert_to_uppercase(lst: List[str]) -> List[str]:
"""
Clone a list and convert all elements to uppercase.
Args:
lst (List[str]): The list of strings to clone and convert.
... |
code_exercise_27k | 7,617 | Write a Python function to clone a list and convert all elements to uppercase. The function should handle lists containing strings and numbers. For numbers, the function should convert them to their string representation and then to uppercase. The code should start with:
```python
from typing import List, Union
def cl... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def clone_and_convert_to_uppercase(lst: List[Union[str, int]]) -> List[str]:
"""
Clones a list and converts all elements to uppercase.
Args:
lst (List[Union[str, int]]): The list to b... |
code_exercise_27k | 7,624 | Write a Python function to combine the values of two dictionaries into a single list. If the dictionaries have common keys, the values from the second dictionary should overwrite the values from the first dictionary. The function should return a dictionary where the values are lists containing the combined values from ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Any
def combine_dict_values(dict1: Dict[Any, Any], dict2: Dict[Any, Any]) -> Dict[Any, list]:
"""
Combine the values of two dictionaries into a single dictionary where each key's value is a list contain... |
code_exercise_27k | 7,631 | Write a Python function to clone a list and calculate the cumulative sum of its elements. The function should return the cloned list with cumulative sums. The code should start with:
```python
from typing import List
def clone_and_cumulative_sum(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 clone_and_cumulative_sum(lst: List[int]) -> List[int]:
"""
Clones a list and calculates the cumulative sum of its elements.
Args:
lst (List[int]): The input list of integers.
Return... |
code_exercise_27k | 7,632 | Write a Python function to clone a list and calculate the product of all even elements in the cloned list. The function should handle the following:
1. Clone the input list.
2. Calculate the product of all even elements in the cloned list.
3. Return the product.
4. Raise a `TypeError` if the input is not a list.
5. Rai... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def clone_and_calculate_product(lst: List[int]) -> int:
"""
Clones the input list and calculates the product of all even elements in the cloned list.
Args:
lst (List[int]): The input list to... |
code_exercise_27k | 7,634 | Write a Python function to count the frequency of each word in a given sentence using a dictionary. The function should handle case insensitivity and ignore punctuation marks. The code should start with:
```python
from typing import Dict
def count_word_frequency(sentence: str) -> Dict[str, int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_word_frequency(sentence: str) -> Dict[str, int]:
"""
Count the frequency of each word in a given sentence using a dictionary.
Parameters:
sentence (str): The input sentence.
Retur... |
code_exercise_27k | 7,636 | Write a Python function to create a dictionary from a list of strings, where the keys are the strings and the values are the lengths of the strings. The function should handle an empty list gracefully and return an empty dictionary in that case. The code should start with:
```python
from typing import List, Dict
def c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_string_length_dict(strings: List[str]) -> Dict[str, int]:
"""
Create a dictionary from a list of strings where the keys are the strings and the values are the lengths of the strings.
... |
code_exercise_27k | 7,637 | Write a Python function to clone a list and calculate the product of all odd elements in the cloned list. The function should handle the following cases:
- If the input is not a list, raise a `TypeError`.
- If the input list is empty, raise a `ValueError`.
- The function should return the product of all odd elements in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def clone_and_calculate_product(lst: List[int]) -> int:
"""
Clones a list and calculates the product of all odd elements in the cloned list.
Args:
lst (List[int]): The list to be cloned and ... |
code_exercise_27k | 7,638 | Write a Python function to calculate the sum of all integer values in a nested dictionary. The function should handle dictionaries that may contain other dictionaries as values, and it should sum all integer values found at any level of nesting. The code should start with:
```python
from typing import Dict
def sum_nes... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def sum_nested_dict_values(nested_dict: Dict) -> int:
"""
Calculate the sum of all integer values in a nested dictionary.
Args:
nested_dict (Dict): A nested dictionary containing integer val... |
code_exercise_27k | 7,639 | Write a Python function to insert an element at a position in a list where the difference between the sum of the cubes of the previous N elements and the sum of the cubes of the next N elements is minimized. The function should handle cases where the list length is less than 2*N + 1 by raising a `ValueError`.
The code... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def insert_element_with_min_cube_diff(lst: List[Union[int, float]], element: Union[int, float], N: int) -> List[Union[int, float]]:
"""
Inserts an element at a position in the list where the diffe... |
code_exercise_27k | 7,640 | Write a Python function to clone a list and find the index of the last occurrence of a specific element in the cloned list. The function should return the index of the last occurrence of the element if it exists, otherwise, it should return -1. The function should also handle cases where the input is not a list by rais... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def clone_and_find_last_occurrence(lst: List[Any], element: Any) -> int:
"""
Clone a list and find the index of the last occurrence of a specific element.
Args:
lst (List[Any]): The lis... |
code_exercise_27k | 7,642 | Write a Python function to remove and return the last element from a given list using the `pop()` method. The function should handle the case where the list is empty by raising an `IndexError` with a specific message. The code should start with:
```python
from typing import Any, List
def remove_last_element(my_list: L... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Any, List
def remove_last_element(my_list: List[Any]) -> Any:
"""
Remove and return the last element from a given list using the pop() method.
Args:
my_list (List[Any]): The list from which the l... |
code_exercise_27k | 7,643 | Write a Python function to clone a list and remove all elements at odd indices. The function should return the modified cloned list. The code should start with:
```python
from typing import List
def clone_and_remove_odds(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 clone_and_remove_odds(lst: List[int]) -> List[int]:
"""
Clones a list and removes all elements at odd indices.
Args:
lst (List[int]): The input list to clone and modify.
Returns:
... |
code_exercise_27k | 7,644 | Write a Python function to generate a new dictionary that includes only the specified keys from a given dictionary. If a specified key does not exist in the original dictionary, it should be ignored. The function should handle cases where the original dictionary or the list of keys is empty.
The code should start with... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List
def generate_dictionary_with_keys(original_dict: Dict[str, any], keys: List[str]) -> Dict[str, any]:
"""
Generates a new dictionary with only the specified keys from a given dictionary.
Args:
... |
code_exercise_27k | 7,645 | Write a Python function to remove and return the last element from a list using the `pop()` method. The function should handle the case where the list is empty by raising an `IndexError` with a specific message. The code should start with:
```python
from typing import List
def pop_last_element(lst: List) -> any:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def pop_last_element(lst: List) -> any:
"""
Remove and return the last element from a list using the pop() method.
Args:
lst (List): The list from which the last element needs to be removed.... |
code_exercise_27k | 7,646 | Write a Python function to add a given number of days to a given date. The function should take a date string in the format "YYYY-MM-DD" and an integer representing the number of days to add. The function should return the resulting date as a string in the same format.
The code should start with:
```python
from dateti... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime, timedelta
def add_days(date_str: str, num_days: int) -> str:
"""
Adds a given number of days to a given date.
Args:
date_str (str): A string representing the date in the format "YYYY-... |
code_exercise_27k | 7,647 | Write a Python function to remove and return the element at a specified index from a given list using the `pop()` method. If the specified index is out of bounds, the function should return `None` without modifying the list.
The code should start with:
```python
from typing import List, Any
def remove_and_return_elem... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def remove_and_return_element(my_list: List[Any], index: int) -> Any:
"""
Remove and return the element at the specified index from the given list.
If the index is out of bounds, return None wit... |
code_exercise_27k | 7,652 | Write a Python function to clone a list and reverse the order of elements between two specified indices. The function should handle edge cases such as invalid indices and empty lists. The code should start with:
```python
from typing import List
def clone_and_reverse_between_indices(lst: List[int], start_index: int, e... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def clone_and_reverse_between_indices(lst: List[int], start_index: int, end_index: int) -> List[int]:
"""
Clones the given list and reverses the order of elements between the specified start and end indi... |
code_exercise_27k | 7,654 | Write a Python function to remove and return the element at a specified index from a list using the `pop()` method. The function should handle cases where the specified index is out of bounds by returning `None` instead of raising an `IndexError`.
The code should start with:
```python
from typing import List, Any
def... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def remove_and_return_element(my_list: List[Any], index: int) -> Any:
"""
Removes and returns the element at the specified index from a list.
Args:
my_list (List[Any]): The input li... |
code_exercise_27k | 7,657 | Write a Python function to remove and return the middle element from a list with an odd number of elements using the `pop()` method. If the list has an even number of elements, raise a `ValueError`. The function should be named `remove_middle_element` and should start with:
```python
from typing import List, Any
def r... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def remove_middle_element(lst: List[Any]) -> Any:
"""
Removes and returns the middle element from a list with an odd number of elements using the pop() method.
Args:
lst (List[Any]): Th... |
code_exercise_27k | 7,660 | Write a Python function to remove and return the middle element from a list with an even number of elements using the `pop()` method. If the list has an odd number of elements, the function should return `None`. The function should handle edge cases such as an empty list and lists with an odd number of elements.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def remove_middle_element(lst: List[Any]) -> Any:
"""
Removes and returns the middle element from a list with an even number of elements.
If the list has an odd number of elements or is empty, r... |
code_exercise_27k | 7,661 | Write a Python function to clone a list and shift all elements to the left by a given number of positions. The function should handle cases where the number of positions to shift is greater than the length of the list by taking the modulo of the number of positions with the length of the list. The function should also ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def shift_list_left(lst: List[int], num_positions: int) -> List[int]:
"""
Clones a list and shifts all elements to the left by a given number of positions.
Args:
- lst (List[int]): The list ... |
code_exercise_27k | 7,664 | Write a Python function to remove all occurrences of a specified element from a given list. The function should return the modified list. If the element is not present in the list, the function should return the original list unchanged.
The code should start with:
```python
from typing import List
def remove_all_occu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_all_occurrences(lst: List[int], element: int) -> List[int]:
"""
Remove all occurrences of a specified element from a given list.
Args:
lst (List[int]): The original list from whic... |
code_exercise_27k | 7,665 | Write a Python function to determine the number of days in a given month and year. The function should accept the year and month as integers and return the number of days in that month. The function should handle leap years correctly for the month of February.
The code should start with:
```python
from typing import T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def get_days_in_month(year: int, month: int) -> int:
"""
Calculate the number of days in a given month and year.
Args:
year (int): The year in YYYY format.
month (int): The month in... |
code_exercise_27k | 7,666 | Write a Python function to clone a list and remove duplicate adjacent elements. The function should return a new list that is a copy of the original list with all duplicate adjacent elements removed. The function should start with:
```python
from typing import List
def clone_and_remove_adjacent_duplicates(lst: List[in... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def clone_and_remove_adjacent_duplicates(lst: List[int]) -> List[int]:
"""
Clone a list and remove duplicate adjacent elements.
Args:
lst (List[int]): The original list.
Returns:
... |
code_exercise_27k | 7,669 | Write a Python function to clone a list and extract all unique elements from it. The function should return a new list containing only the unique elements from the original list, maintaining the order of their first appearance. The code should start with:
```python
from typing import List
def clone_and_extract_unique_... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def clone_and_extract_unique_elements(lst: List[int]) -> List[int]:
"""
Clones a list and extracts all the unique elements from it, maintaining the order of their first appearance.
Args:
lst... |
code_exercise_27k | 7,670 | Write a Python function to remove and return a random element from a given list using the `pop()` method. The function should handle the case where the list is empty by raising an `IndexError`. The code should start with:
```python
from typing import List, Any
import random
def remove_random_element(my_list: List[Any]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
import random
def remove_random_element(my_list: List[Any]) -> Any:
"""
Remove and return a random element from a given list using the pop() method.
Args:
my_list (List[Any]): The list ... |
code_exercise_27k | 7,673 | Write a Python function to remove and return the second-to-last element from a given list using the `pop()` method. The function should handle cases where the list has fewer than two elements by raising an `IndexError`. The code should start with:
```python
from typing import List, Union
def remove_second_to_last_elem... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def remove_second_to_last_element(nums: List[Union[int, float]]) -> Union[int, float]:
"""
Remove and return the second-to-last element from a list.
This function takes a list of numbers as i... |
code_exercise_27k | 7,675 | Write a Python function to remove and return the third-to-last element from a given list using the `pop()` method. If the list does not have enough elements, raise an `IndexError` with a specific message.
The code should start with:
```python
from typing import List, Any
def remove_third_to_last(my_list: List[Any]) -... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def remove_third_to_last(my_list: List[Any]) -> Any:
"""
Remove and return the third-to-last element from a given list using the pop() method.
Args:
my_list (List[Any]): The input list ... |
code_exercise_27k | 7,679 | Write a Python function to remove and return the second youngest element from a given list of ages. The function should use the `pop()` method to remove elements from the list. The code should start with:
```python
from typing import List
def remove_second_youngest_age(ages: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_second_youngest_age(ages: List[int]) -> int:
"""
Removes and returns the second youngest element from a list of ages.
Args:
ages (List[int]): A list of ages.
Returns:
... |
code_exercise_27k | 7,680 | Write a Python function to clone a list and move all zeros to the end while maintaining the order of the non-zero elements. The function should return the modified cloned list. The code should start with:
```python
from typing import List
def clone_and_move_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 clone_and_move_zeros(lst: List[int]) -> List[int]:
"""
Clones a list and moves all zeros to the end while maintaining the order of non-zero elements.
Args:
lst (List[int]): The input lis... |
code_exercise_27k | 7,683 | Write a Python function to find the maximum element in a set. The function should handle the case where the set is empty by raising a `ValueError`. The code should start with:
```python
def find_max_element(s: set) -> object:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_max_element(s: set) -> object:
"""
Find the maximum element in a set.
Parameters:
s (set): The set in which to find the maximum element.
Returns:
object: The maximum element in the set.
Raises:
... |
code_exercise_27k | 7,684 | Write a Python function to clone a given list and move all negative elements to the front while preserving the order of non-negative elements. The function should return the modified clone of the list.
The code should start with:
```python
from typing import List
def clone_and_move_negatives(lst: List[int]) -> List[i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def clone_and_move_negatives(lst: List[int]) -> List[int]:
"""
Clones a given list and moves all negative elements to the front while preserving the order of non-negative elements.
Args:
lst... |
code_exercise_27k | 7,686 | Write a Python function to perform the union of two sets and return the result. The function should handle sets of any size and type, including empty sets. The code should start with:
```python
def set_union(set1: set, set2: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def set_union(set1: set, set2: set) -> set:
"""
Perform the union of two sets and return the result.
Args:
set1 (set): The first set.
set2 (set): The second set.
Returns:
set: The union of set1 ... |
code_exercise_27k | 7,687 | Write a Python function to find the intersection of two sets, which are represented as lists of integers. The function should return the intersection as a list of integers, sorted in ascending order. The code should start with:
```python
from typing import List
def find_intersection(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 find_intersection(list1: List[int], list2: List[int]) -> List[int]:
"""
Finds the intersection of two lists of integers and returns the result as a sorted list.
Args:
list1 (List[int]): ... |
code_exercise_27k | 7,690 | Write a Python function to clone a list and group its elements based on their parity (even/odd). The function should return a dictionary where the keys are 'even' and 'odd', and the values are lists containing the even and odd elements of the original list, respectively. The code should start with:
```python
from typin... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def clone_and_group_list(lst: List[int]) -> Dict[str, List[int]]:
"""
Clones a list and groups its elements based on their parity (even/odd).
Args:
lst (List[int]): The list to be clon... |
code_exercise_27k | 7,691 | Write a Python function to calculate the symmetric difference between two sets. The symmetric difference of two sets is a set of elements that are in either of the sets but not in their intersection. The code should start with:
```python
def symmetric_difference(set1: set, set2: set) -> set:
```
| 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 a set of elements that are in either of the sets
but not in their i... |
code_exercise_27k | 7,695 | Write a Python function to remove and return elements with odd indices from a given list using the `pop()` method. The function should handle lists of any length, including empty lists. The function 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 and returns elements with odd indices from a given list using the pop() method.
Args:
lst (List[int]): The list from which el... |
code_exercise_27k | 7,696 | Write a Python function to check if one set is a subset of another set. The function should return `True` if all elements of the first set are present in the second set, and `False` otherwise. The function should handle sets of any size and type of elements.
The code should start with:
```python
def is_subset(set1: se... | 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.
Args:
set1 (set): The first set to check.
set2 (set): The second set to check against.
Returns:
bool: True if ... |
code_exercise_27k | 7,698 | Write a Python function to clone a list and find the largest continuous sum of elements in the cloned list. The function should return both the cloned list and the largest continuous sum. If the input list is empty, the function should raise a `ValueError`.
The code should start with:
```python
from typing import List... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def clone_list_and_find_largest_sum(lst: List[int]) -> Tuple[List[int], int]:
"""
Clones a list and finds the largest continuous sum of elements in the cloned list.
Args:
lst (List[in... |
code_exercise_27k | 7,701 | Write a Python function to clone a list and find the first repeating element in the cloned list. The function should return the first repeating element if found, otherwise return `None`. The code should start with:
```python
from typing import List, Any
def find_first_repeating_element(lst: List[Any]) -> Any:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Any
def find_first_repeating_element(lst: List[Any]) -> Any:
"""
Clone a list and find the first repeating element in the cloned list.
Args:
lst (List[Any]): The input list to be cloned and... |
code_exercise_27k | 7,708 | Write a Python function to clone a list and find the elements that occur exactly once in the cloned list. The function should return a list of these unique elements. The code should start with:
```python
from typing import List
def find_unique_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 find_unique_elements(lst: List[int]) -> List[int]:
"""
Clones a list and finds the elements that occur exactly once in the cloned list.
Args:
lst (List[int]): The list to clone and find ... |
code_exercise_27k | 7,713 | Write a Python function to clone a given list of numbers and find the kth smallest element in the cloned list. The function should handle the cloning of the list and the sorting of the cloned list to find the kth smallest element efficiently. The function should also raise an `IndexError` if the value of `k` is out of ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def clone_and_find_kth_smallest(numbers: List[int], k: int) -> int:
"""
Clones a given list of numbers and finds the kth smallest element in the cloned list.
Args:
numbers (List[int]): The l... |
code_exercise_27k | 7,716 | Write a Python function to find the common elements between two sets and return them as a sorted list. The function should handle cases where the input sets are empty or have no common elements. The code should start with:
```python
from typing import List
def find_common_elements(set1: set, set2: set) -> List[int]:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_common_elements(set1: set, set2: set) -> List[int]:
"""
Find the common elements between two sets and return them as a sorted list.
Args:
set1 (set): The first set.
set2 (se... |
code_exercise_27k | 7,718 | Write a Python function to remove and return the last three elements from a given list using the `pop()` method. If the list has fewer than three elements, raise a `ValueError`. The function should start with:
```python
from typing import List
def remove_last_three_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_last_three_elements(lst: List[int]) -> List[int]:
"""
Removes and returns the last three elements from a given list.
Args:
lst (List[int]): The input list from which to remove the... |
code_exercise_27k | 7,722 | Write a Python function to remove and return the first and last elements from a given list using the `pop()` method. The function should handle cases where the list is empty or has only one element. If the list is empty, the function should return `None`. If the list has only one element, the function should return tha... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple, Optional
def remove_first_and_last_elements(lst: List[int]) -> Optional[Tuple[int, int]]:
"""
Removes and returns the first and last elements from a list.
Args:
lst (List[int]): The ... |
code_exercise_27k | 7,725 | Write a Python function to clone a list and find the median of all elements in the cloned list. The function should handle both odd and even lengths of the list and return the median value. If the input list is empty, the function should raise a `ValueError`.
The code should start with:
```python
from typing import Li... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def clone_and_find_median(lst: List[int]) -> float:
"""
Clone a list and find the median of all elements in the cloned list.
Args:
lst (List[int]): The input list of integers.
Returns:
... |
code_exercise_27k | 7,727 | Write a Python function to generate a list of all the Mondays between two given dates. The function should take two `datetime` objects as input, representing the start and end dates, and return a list of `datetime` objects representing all the Mondays within that range, inclusive of the start and end dates if they are ... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime, timedelta
def generate_mondays(start_date: datetime, end_date: datetime) -> list:
"""
Generate a list of all the Mondays between two given dates.
Args:
start_date (datetime): The star... |
code_exercise_27k | 7,733 | Write a Python function to calculate the mean value of all elements in a given set. If the set is empty, raise a `ValueError` with the message "The input set cannot be empty." The function should be able to handle sets containing integers and floating-point numbers.
The code should start with:
```python
def find_mean(... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_mean(s: set) -> float:
"""
Calculate the mean value of all elements in a set.
Args:
s (set): The input set containing integers and/or floating-point numbers.
Returns:
float: The mean value of t... |
code_exercise_27k | 7,736 | Write a Python function to clone a list and find the length of the longest increasing subarray in the cloned list. The function should return both the cloned list and the length of the longest increasing subarray.
The code should start with:
```python
from typing import List, Tuple
def clone_and_find_longest_increasi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def clone_and_find_longest_increasing_subarray(original_list: List[int]) -> Tuple[List[int], int]:
"""
Clone a given list and find the length of the longest increasing subarray in the cloned list.... |
code_exercise_27k | 7,740 | Write a Python function to clone a list and find the length of the longest common subsequence (LCS) between the original list and the cloned list. The function should return both the cloned list and the length of the LCS.
The code should start with:
```python
from typing import List, Tuple
def clone_and_find_lcs(lst:... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def clone_and_find_lcs(lst: List[int]) -> Tuple[List[int], int]:
"""
Clones a given list and finds the length of the longest common subsequence (LCS) between the original and the cloned list.
... |
code_exercise_27k | 7,750 | Write a Python function to check if all elements in a given set `set_a` are also present in another given set `set_b`. The function should return `True` if all elements in `set_a` are present in `set_b`, and `False` otherwise. The code should start with:
```python
def are_all_elements_present(set_a: set, set_b: set) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
def are_all_elements_present(set_a: set, set_b: set) -> bool:
"""
Check if all elements in Set A are also present in Set B.
Args:
set_a (set): The first set to check.
set_b (set): The second set to check.
... |
code_exercise_27k | 7,752 | Write a Python function to remove and return the first three elements from a given list using the `pop()` method. If the list has fewer than three elements, raise an `IndexError` with a specific message. The function should start with:
```python
from typing import List
def remove_and_return_first_three_elements(my_lis... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_and_return_first_three_elements(my_list: List[int]) -> List[int]:
"""
Remove and return the first three elements from a given list.
Args:
my_list (List[int]): The list from which ... |
code_exercise_27k | 7,758 | Write a Python function to clone a list and find the elements that occur exactly `k` times in the cloned list. The function should return a list of these elements. The code should start with:
```python
from typing import List
def find_elements_occurring_k_times(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_occurring_k_times(lst: List[int], k: int) -> List[int]:
"""
Clones a list and finds the elements that occur exactly k times in the cloned list.
Args:
lst (List[int]): The i... |
code_exercise_27k | 7,763 | Write a Python function to check if a given set is a subset of another set. The function should return `True` if all elements of the first set are present in the second set, and `False` otherwise. The function should handle sets of any size, including empty sets.
The code should start with:
```python
def is_subset(sub... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_subset(subset: set, superset: set) -> bool:
"""
Check if a given set is a subset of another set.
Args:
subset (set): The set to be checked if it's a subset.
superset (set): The set to compare against.... |
code_exercise_27k | 7,764 | Write a Python function to add a specified number of seconds to a given `datetime` object. The function should handle both positive and negative values for the number of seconds to be added. The code should start with:
```python
from datetime import datetime, timedelta
def add_seconds_to_datetime(datetime_obj: datetim... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime, timedelta
def add_seconds_to_datetime(datetime_obj: datetime, seconds: int) -> datetime:
"""
Adds a specified number of seconds to a given datetime object.
Args:
datetime_obj (datetim... |
code_exercise_27k | 7,765 | Write a Python function to remove and return the first element, the last element, and the element at index 2 from a given list using the `pop()` method. The function should return these elements in a tuple, with the first element of the tuple being the element at index 2, the second element being the first element, and... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def remove_elements(lst: List[int]) -> Tuple[int, int, int]:
"""
Removes and returns the first element, the last element, and the element at index 2 from a list.
Args:
lst (List[int])... |
code_exercise_27k | 7,767 | Write a Python function to check if a given set is a superset of another set. The function should return `True` if the first set contains all elements of the second set, and `False` otherwise. The code should start with:
```python
def is_superset(set_a: set, set_b: set) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_superset(set_a: set, set_b: set) -> bool:
"""
Check if a given set (set_a) is a superset of another set (set_b).
Args:
set_a (set): The given set to check if it is a superset.
set_b (set): The other s... |
code_exercise_27k | 7,777 | Write a Python function to determine the week number of a given date. The function should accept either a string in the format 'YYYY-MM-DD' or a `datetime.date` object as input and return the week number as an integer. The function should handle invalid date formats and unsupported types appropriately by raising except... | Here is the Python code to solve the given problem in the markdown block:
```python
import datetime
def get_week_number(date):
"""
Get the week number from a given date.
Args:
date (str or datetime.date): The input date. If `date` is a string, it should be in the format 'YYYY-MM-DD'.
Returns:... |
code_exercise_27k | 7,779 | Write a Python function to determine if a given set is immutable. An immutable set is one that cannot be modified after it is created. The function should return `True` if the set is immutable and `False` otherwise. The code should start with:
```python
def is_immutable_set(s: set) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def is_immutable_set(s: set) -> bool:
"""
Determine if the given set is immutable.
Args:
s (set): The set to be checked for immutability.
Returns:
bool: True if the set is immutable, False otherwise.
... |
code_exercise_27k | 7,784 | Write a Python function to return a new set containing elements that are in the first set but not in the second set. The function should handle cases where the sets are empty or have overlapping elements. The code should start with:
```python
def difference_set(first_set: set, second_set: set) -> set:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def difference_set(first_set: set, second_set: set) -> set:
"""
Returns a new set containing elements that are in the first set but not in the second set.
Args:
first_set (set): The first set to compare.
sec... |
code_exercise_27k | 7,786 | Write a Python function to remove and return the element at index `-4` and the last element from a given list using the `pop()` method. The function should handle cases where the list is too short to perform the operation by raising an `IndexError`.
The code should start with:
```python
from typing import List, Tuple
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def remove_elements_from_list(lst: List[int]) -> Tuple[int, int]:
"""
Removes and returns the element at index -4 and the last element from the given list.
Args:
lst (List[int]): The ... |
code_exercise_27k | 7,788 | Write a Python function to check if two sets have the same elements, regardless of their order. The function should return `True` if the sets have the same elements, and `False` otherwise. The code should start with:
```python
def check_same_elements(set1: set, set2: set) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def check_same_elements(set1: set, set2: set) -> bool:
"""
Check if two sets have the same elements, regardless of their order.
Args:
set1 (set): The first set to compare.
set2 (set): The second set to compa... |
code_exercise_27k | 7,795 | Write a Python function to check if a given date is valid. The date should be provided as a string in the format "YYYY-MM-DD". The function should return `True` if the date is valid and `False` otherwise. The function should also handle leap years correctly.
The code should start with:
```python
def is_valid_date(date... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_valid_date(date: str) -> bool:
"""
Check if a given date is valid.
Args:
date (str): The date to be checked in the format "YYYY-MM-DD".
Returns:
bool: True if the date is valid, False otherwise.
... |
code_exercise_27k | 7,796 | Write a Python function to find the symmetric difference between two given sets. The symmetric difference of two sets is defined as the set of elements which are in either of the sets but not in both. The function should handle input validation to ensure that both inputs are sets. The code should start with:
```python
... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_symmetric_difference(set1, set2):
"""
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.
Args:
... |
code_exercise_27k | 7,799 | Write a Python function to find the symmetric difference between two given sets. The symmetric difference between two sets is defined as the set of elements that are present in either of the sets but not in both. The function should handle any type of set elements, including numbers, strings, and other hashable objects... | 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 between two sets, also known as the disjunctive union, is the set of elements that are... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.