task_id
prompts_rust.parquet
comparing changes between versions
prompt
rust_prompt
rust_code
task_id
prompt
task_181
Create a function that takes a given string and returns a dictionary containing the frequency of each alphabet character in the string, along with a list of the characters that appear most frequently and a list of the characters that appear least frequently. The function should ignore non-alphabet characters and treat uppercase and lowercase letters as the same (i.e., 'A' = 'a'). If the string is empty, return a message indicating that the string is empty.
task_38
Develop a function to identify the third largest unique number in a multidimensional array. The function should handle negative numbers and return 'None' if the array has less than three unique numbers. Additionally, the function should be able to handle arrays of varying depths and should ignore non-numeric values such as strings and booleans. The function should also be optimized to handle large arrays, potentially containing more than 10,000 elements.
task_196
Given a 2D array representing pixel values of an image, convert it into a 1D byte string representation. The array can have either 3 channels (RGB) or 4 channels (RGBA). If the input array has 3 channels, the output should contain the pixel values in the order of RGB. If it has 4 channels, the output should contain the pixel values in the order of RGBA. Each pixel value is represented as an integer in the range of 0 to 255. Write a function `array_to_byte_string(image_array: List[List[Tuple[int, int, int]]]) -> bytes` that takes the 2D array as input and returns the corresponding byte string.
task_150
Given a date of birth in the format 'DD MM YYYY', implement a function that returns the name of the day of the week for that date. The function should take one parameter, a string representing the date of birth. For example, the date '3 5 1985' should return 'Friday'.
task_90
Given a dictionary, write a function that takes a value as input and returns a list of keys corresponding to that value, along with the count of those keys. Also, return the total number of pairs in the input dictionary that have duplicate values. The function should return a tuple containing the list of keys, the count of keys, and the number of pairs with duplicate values. For example, if the input dictionary is {'a': 1, 'b': 2, 'c': 2, 'd': 3, 'e': 1, 'f': 4, 'g': 2} and the input value is 2, the output should be (['b', 'c', 'g'], 3, 5).
task_190
Given a floating-point number n, your task is to implement a function that finds the largest prime factor of the absolute integer part of n. The number will always have a magnitude greater than 1 and will never be prime. Implement the function `accurate_largest_prime_factor(n: float) -> int`.
task_165
Given a function `is_valid_limit(resource: Any, value: int) -> bool`, determine if the specified limit for the number of matching resources is valid. A limit is considered valid if it is greater than zero. The function should return `True` if the limit is valid, and `False` otherwise. The `resource` parameter is not used in the validation, and can be of any type. The `value` parameter is an integer that represents the specified limit. Implement the function to solve this problem.
task_126
Given a list of 20 float values representing cosmological parameters, implement a function that calculates the average of these values and returns it. The input will be a list of floats that contain the following values: [0.969, 0.654, 1.06, 0.703, 1.1615, 0.759, 0.885, 0.6295, 0.605, 0.7205, 1.1685, 1.179, 0.857, 1.123, 0.843, 0.5245, 0.99, 0.7485, 0.528, 1.1265].
task_80
Given a list of deposit and withdrawal operations on a bank account starting with a zero balance, detect if at any point the balance falls below zero or equals zero based on the operations performed. Your function should take in a list of tuples, where each tuple contains an operation type (either 'Deposit' or 'Withdrawal') and an operation value as a string that can be converted into a Decimal. Additionally, include an optional case_insensitive flag that allows the function to treat 'Deposit' and 'deposit', as well as 'Withdrawal' and 'withdrawal', as the same operation. The function should also handle incorrectly formatted input tuples gracefully. Return True if the balance falls below zero or equals zero in a case-insensitive context; otherwise, return False. The input will be guaranteed to be a list of tuples, but the contents of the tuples may not always be valid. Ensure that your implementation can handle arbitrary precision arithmetic for the operation values.
task_111
Given a list of distinct strings, implement a function that finds the index of a specified target string within that list. If the target string is not found, the function should return -1. Write a function named `find_position(words: List[str], target: str) -> int` that takes a list of strings and a target string as inputs.
task_137
Given a list of filenames and a start date, write a function that returns a list of filenames that contain the substring 'prmsl' and have a date (in 'YYYY-MM-DD_HH' format) that is older than the provided start date. The filenames are assumed to be formatted with a date and time component that can be extracted using regex. The start date is provided as a string in the 'YYYY-MM-DD' format. You need to implement the function `filter_prmsl_files(file_list: List[str], start_date: str) -> List[str]` where `file_list` is a list of strings representing the filenames and `start_date` is a string representing the date in 'YYYY-MM-DD' format. The output should be a list of filenames that meet the criteria.
task_30
Given a list of integers, implement a function that returns the original list and a new list containing the same integers sorted in ascending order. Your function should have the following signature: `def process_list(arr: List[int]) -> Tuple[List[int], List[int]]`.
For example, given the input `arr = [5, 2, 7, 1, 9]`, the function should return:
1. Original array: `[5, 2, 7, 1, 9]`
2. Sorted array: `[1, 2, 5, 7, 9]`.
task_155
Given a list of integers, write a function that returns the sum of all even numbers in the list. If there are no even numbers, return 0. Your function should handle an empty list as well.
task_39
Given a list of integers, you need to implement a function that constructs a Binary Search Tree (BST) from the list. The function should return the root node of the constructed BST. You can assume that the input list contains distinct integers. The BST should be constructed such that for any node, all values in the left subtree are smaller and all values in the right subtree are larger. Implement the function `construct_bst(values: List[int]) -> TreeNode:` where `TreeNode` is a class that has attributes `val`, `left`, and `right`.
task_127
Given a list of strings (lexemes), implement a function that reverses the order of the lexemes in the list. The function should take a single parameter, which is the list of strings, and return a new list with the lexemes in reverse order.
task_92
Given a list of strings that contain both alphabetic and numeric characters, implement a function that sorts the list based on the numeric part of each string in ascending order. The strings can be in any format but will always contain at least one numeric character. Return the sorted list.
task_156
Given a list of strings where each string is in the format 'name_date', implement a function `decompose_names(dates)` that splits each string into a tuple of (`name`, `date`). The `name` is the part before the last underscore ('_') and the `date` is the part after the last underscore. The `date` should also have all spaces removed. The function should return a list of tuples containing the decomposed names and dates. For example, given the input ['Alice_2023-03-15', 'Bob_2023-03-16'], the output should be [('Alice', '2023-03-15'), ('Bob', '2023-03-16')].
task_73
Given a list of symbols (strings) and an ordered list of elements (also strings), implement a function that transforms each symbol in the list to its corresponding index in the ordered list. If a symbol does not exist in the ordered list, return -1 for that symbol. The function should return a list of integers representing these indices.
Function signature: `def transform_symbols_to_indices(symbols: Union[str, List[str]], order: List[str]) -> List[int]:`
Example:
- Input: `symbols = ['a', 'b', 'c']`, `order = ['c', 'b', 'a']`
- Output: `[2, 1, 0]`
Constraints:
- The `symbols` input can be either a single string or a list of strings.
- The `order` input must be a list of strings.
task_178
Given a list of tokens (words) and a target sentence length, implement a function that transforms the input tokens into a 2D array of shape (sentence_length, 50), where the first dimension corresponds to the padded sentence length, and the second dimension is fixed at 50. If the number of tokens is less than the sentence length, the remaining entries should be filled with zeros (representing padding). If the number of tokens exceeds the sentence length, truncate the tokens to fit the required length. The function should return the resulting 2D array as a list of lists, where each inner list represents a padded or truncated token encoding.
task_94
Given a multidimensional array `result` that contains stellar mass function (SMF), blue fraction, and stellar mass-halo mass (SMHM) information, along with two arrays `gals_bf` and `halos_bf` representing the best fit stellar and halo mass values, and a float `bf_chi2` representing the chi-squared value of the best-fit model, your task is to compute the maximum and minimum values of the y-axis stellar mass values from the `result` array across different models. Specifically, you need to implement a function `compute_max_min_smhm(result: List[List[List[float]]], gals_bf: List[float], halos_bf: List[float], bf_chi2: float) -> Tuple[float, float]` that returns a tuple containing the maximum and minimum stellar mass values derived from the data in `result`.
task_16
Given a n-ary tree, write a function to determine if two given values are cousins. Two nodes are cousins if they have the same depth but different parents. You need to implement the function `areCousins(root: Node, x: int, y: int) -> bool`, where `Node` is defined as a class with properties `val` (the value of the node) and `children` (a list of its child nodes).
task_25
Given a registration token for a user, implement a function `cancel_registration_with_token(token: str) -> str` that checks if the token contains an email claim. If the token does not contain an email claim, the function should return 'Invalid token: email claim missing'. Otherwise, return 'Registration canceled successfully'. The email claim is considered valid if it is present and is a non-empty string in the token. You may assume the token is a simple string for this exercise.
task_136
Given a string `type`, write a function `is_volatile(type: str) -> bool` that determines if the given C++ type is a volatile type. A volatile type is defined as one that contains the keyword 'volatile' (case-sensitive) in its representation. The function should return `True` if the type is volatile and `False` otherwise. Example input: 'volatile int', 'const volatile float', 'int', 'volatile'; Example output: True, True, False, True.
task_12
Given a string representation of a rust value, implement a function that formats the string to return just the actual value contained in it. The string representation may include single quotes, Unicode notation, or class type indications. For example, if the input is "'hello'", the output should be "hello". If the input is "u'world'", the output should be "world". If the input is "<class 'str'>", the output should be "str". If the input does not match any of these formats, return the original string. Write a function `format_param_value(value_repr: str) -> str` that will take a single string input and return the formatted value as a string.
task_176
Given a string representing a bucket name, write a function that returns a list of keys in the bucket. The keys are represented as filenames in a directory structure that corresponds to the bucket name. You can assume that the directory structure is represented as a list of strings where each string is a filename in the specific bucket. Your function should return the keys as a list of strings. The function signature is as follows: `def list_keys(bucket: str, files: List[str]) -> List[str]:` where `files` is a list containing all the filenames in the bucket.
task_135
Given a string representing a mathematical expression composed of integers and the operators +, -, *, /, implement a function `evaluate_expression(expr: str) -> float` that evaluates the expression and returns the result. The expression is guaranteed to be valid and will not contain any whitespace.
task_69
Given a string that represents a full module path and an attribute name in the format 'module_name.attribute_name', write a function that splits this string into two parts: the module name and the attribute name. The function should return a tuple containing the module name and the attribute name. If the input string is invalid (i.e., not a string or does not contain a '.' character), the function should return None. Implement the function as follows: def split_module_attribute(str_full_module):
task_89
Given a string, implement a function `replace_multiple_spaces` that replaces all occurrences of multiple consecutive whitespace characters with a single space. The function should be able to handle any number of consecutive spaces, tabs, or other whitespace characters. The output should only contain single spaces between words. Write a function that takes a string as input and returns the modified string.
task_61
Given a string, implement a function that returns the length of the longest palindromic subsequence. A palindromic subsequence is a sequence that appears in the same order when read forwards and backwards. For example, in the string 'agbcba', the longest palindromic subsequence is 'abcba' which has a length of 5.
task_116
Given a string, implement a function that reverses the string without using any built-in functions for reversing or modifying strings. The function should return the reversed string.
task_158
Given a time in the format HH:MM:SS, convert it to a specified timezone and return the time in the same format. The input will include the time as a string and the timezone offset in hours (which can be positive or negative). Your task is to implement a function `convert_time(t: str, tz_offset: int) -> str` that takes in the time and timezone offset, and returns the converted time in the format HH:MM:SS. The input time will always be valid and within the range of 00:00:00 to 23:59:59. The output time should also be within this range, wrapping around if necessary (e.g., 23:59:59 with a +1 hour offset should return 00:00:59).
task_23
Given an array of strings representing lines of text, implement a function that finds the index of the first line of the next paragraph starting from a given line index. A paragraph is defined as a sequence of non-empty lines separated by one or more empty lines. Your function should ignore the current paragraph and return the index of the first line of the next paragraph. If there is no next paragraph, return -1. The inputs are: an array of strings `file` and an integer `line` (the zero-based index of the starting line).
task_101
Given an integer n, implement a function that removes all even digits from n, sorts the remaining odd digits in descending order, and returns the resulting integer. If no odd digits remain, return 0.
task_85
Given an integer year, write a function called `is_leap_year(year)` that determines if the given year is a leap year. A leap year is defined as a year that is evenly divisible by 4, except for end-of-century years, which must be divisible by 400 to be considered a leap year. Your function should return True if the year is a leap year, and False otherwise.
task_1
Given the coordinates of a point on the x-axis and the center coordinates of a circle, along with the radius of the circle, write a function `circle_y_coordinate(x: float, r: float, cx: float, cy: float) -> float` that returns the y-coordinate of the point on the circumference of the circle. The y-coordinate should be calculated using the formula for a circle: y = sqrt(r^2 - (x - cx)^2) + cy, where (cx, cy) is the center of the circle. If the point (x, y) does not lie within the circle, the function should return -1. The function should handle cases where the square root calculation results in a negative number by returning -1 for those cases. The inputs are guaranteed to be valid floats.
task_198
Given three points on a Cartesian plane, determine if they can form a right triangle with one vertex at the origin (0,0). If they do form a right triangle, calculate the length of the hypotenuse and the area of the triangle. If they do not form a right triangle, return an appropriate error message. Implement a function that takes in the coordinates as a list of tuples and returns either the hypotenuse and area as a tuple or an error message as a string.
task_66
Given two lists of integers, `attrs_from` and `attrs_to`, write a function `compute_correlations(attrs_from: List[int], attrs_to: List[int]) -> Dict[int, Dict[int, float]]` that computes a correlation score between elements in `attrs_from` and `attrs_to`. The correlation score is defined as follows: if the two elements are the same, the correlation is 1.0. If an element in `attrs_from` is unique (occurs only once) or if there are no elements in `attrs_to`, the correlation is 0.0. Otherwise, for pairs of elements (a, b) where a is from `attrs_from` and b is from `attrs_to`, the correlation score should be computed as 1.0 minus the normalized value of how often the element from `attrs_from` occurs with the element from `attrs_to` compared to the total occurrences of that element. Return the result as a dictionary with the structure: {attr_a: {cond_attr_i: corr_strength_a_i, ...}, attr_b: {...}}.
task_87
Implement a function `deep_copy(obj)` that takes an object and returns a deep copy of that object. A deep copy means that all objects are copied recursively, and changes made to the original object should not affect the copied object. Use rust's built-in `copy` module to implement this functionality.
task_15
Implement a function `depth_first_search(tree: TernaryTree, value: int) -> bool` that performs a depth-first search in a balanced ternary tree to determine if a node with the specified value exists in the tree. The tree is defined by the `TernaryTree` class, which allows for insertion of nodes. Ensure that the tree maintains its balance after each insertion. The function should return `True` if the value is found, and `False` otherwise.
task_0
Implement a function `echo_nums(x, y)` that takes two integers, x and y, and returns a list of all numerical values within the range from x to y, inclusive. The function should handle cases where x is greater than y by returning an empty list.
task_134
Implement a function `extract_and_store_data(url: str) -> None` that fetches data from the provided API URL, processes the data entries, and stores them in a SQLite database. Each data entry consists of UserId, Id, Title, and Body. Ensure that the function handles exceptions during the data fetching and database operations. The function should also insert new entries into the database, avoiding duplicates based on the Id. The database should be created with a table named 'posts' if it does not already exist. Note: You do not need to implement a user interface or a progress indicator, just focus on the data extraction and storage functionality.
task_131
Implement a function `increment_number(x: int) -> int` that takes an integer `x` as input and returns the value of `x` incremented by 1. The function should not print any output; it should simply return the incremented value.
task_81
Implement a function `max_repeating_substring` that determines the substring which appears the most number of times in the given original string. If there are multiple substrings that have the same maximum count, return the first one that appears in the string.
task_13
Implement a function `string_to_md5(text: str) -> Optional[str]` that takes a string `text` as input and returns the MD5 hash of the string in hexadecimal format. If the input string is empty, the function should return None. Make sure to handle the encoding properly.
task_164
Implement a function `third_last_element(head)` that takes the head of a singly linked list and returns the value of the element positioned third from the last in the linked list. If the linked list contains fewer than three elements, return 'LinkedList has less than 3 elements'.
task_36
Implement a function `unusual_addition(lst)` that accepts a list of strings, where each string consists solely of numerical digits. For each string in the list, count the odd and even digits. Replace every occurrence of the digit 'i' in the output string with the count of odd digits in the respective string, and replace every occurrence of the digit 'e' with the count of even digits. The output should be a list of these modified strings, where the output for the i-th string is formatted as: 'the number of odd elements {odd_count}n the str{even_count}ng {even_count} of the {odd_count}nput.' For example, if the input is ['1234567'], the output should be ['the number of odd elements 4n the str3ng 3 of the 4nput.'].
task_117
Implement a function called `sqrt` that computes the square root of a given non-negative number without using any built-in square root functions or libraries. If the input number is negative, the function should raise an exception with the message 'Invalid input! Cannot compute square root of a negative number.' The result should be rounded to 8 decimal places. The input number will be in the range [-10^4, 10^4].
task_32
Implement a function that checks if the provided string contains the exact sequence of characters 'hello'. The function should return True if 'hello' is found within the string, and False otherwise. The search should be case-insensitive.
task_97
Implement a function that converts a given string into a custom leetspeak format. The conversion rules are as follows: 1. Replace vowels with the following: a -> 4, e -> 3, i -> 1, o -> 0, u -> (_). 2. Replace the second instance of each consonant in the string with its ASCII value. 3. Preserve the case of each character in the original string. 4. Ignore spaces and punctuation during the conversion. Write a single function named `convert_to_leetspeak(string)` that takes a string as input and returns the converted leetspeak string.
task_118
Implement a function that counts the number of consonant instances in a given string. The function should ignore spaces, punctuation, and numbers. Consonants are defined as all letters that are not vowels (a, e, i, o, u) and can be either uppercase or lowercase. Your function should return the total instances of consonants present in the input string.
task_63
Implement a function that counts the number of lowercase consonants located at odd index positions in a given string. The function should only consider lowercase letters, and consonants are defined as letters that are not vowels (a, e, i, o, u). Return the count of such consonants found at odd indices in the string.
task_152
Implement a function that determines if a given integer is a narcissistic number or not. A narcissistic number (also known as an Armstrong number) for a given number of digits is a number that is equal to the sum of its own digits each raised to the power of the number of digits. For example, 153 is a narcissistic number because 1^3 + 5^3 + 3^3 = 153. Your function should take an integer n as input and return True if n is a narcissistic number, otherwise return False.
task_161
Implement a function that finds the Least Common Multiple (LCM) of four integers (w, x, y, z). The function should optimize for O(log N) time complexity. You can assume that the input integers will always be positive and in the range of 1 to 10^9. Write a function named 'lcm' that takes four integers as parameters and returns their LCM.
task_6
Implement a function that generates a unique ID in the form of a string and returns it along with the current timestamp in the format 'YYYY-MM-DD HH:MM:SS'. The unique ID should be generated using UUID4. The function should return both the ID and the timestamp as a tuple. Define the function as `generate_unique_id()`.
task_125
Implement a function that generates and returns the Fibonacci sequence up to the n-th number. The function should handle and validate the input, ensuring that it processes only non-negative integers. Additionally, if the input is provided as a string with non-digit characters, the function should ignore those characters and extract the number. If the input cannot be converted to a valid non-negative integer, the function should return an error message. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the two preceding ones. The function should be optimized to handle large values of n.
task_99
Implement a function that generates the Fibonacci sequence for the first n terms. Each number in the sequence should be the sum of the two preceding numbers. The function should raise a ValueError if n is not a positive integer. The function should return a list containing the Fibonacci sequence up to the nth term. Please implement the function `fibonacci(n)`, where n is the number of terms to generate.
task_71
Implement a function that performs Gumbel-Softmax sampling. The function should take in an array of log-probabilities and a temperature parameter, and return an array of samples drawn from the Gumbel-Softmax distribution. The Gumbel-Softmax distribution is defined as:
y_i = exp((g_i + log_pi_i) / tau) / sum_j(exp((g_j + log_pi_j) / tau)),
where g_i are samples drawn from a Gumbel distribution. Your function should handle cases where the input log-probabilities array is empty.
Function Signature:
def gumbel_softmax(log_pi: List[float], tau: float) -> List[float]:
task_114
Implement a function that performs subtraction of two integers. The function should take two parameters, `a` and `b`, which represent the integers to be subtracted, and return the result of `a - b`.
task_133
Implement a function that takes a date string formatted as 'DD MMM YYYY' (where 'MMM' is the three-letter abbreviation for the month) and returns the corresponding day, month, and year as a tuple of integers. For example, given the input '01 Jan 2018', the output should be (1, 1, 2018).
task_186
Implement a function that takes a list of integers, an integer n, and an integer k. The function should return a new list where for each index in the original list, if the index is divisible by n, the corresponding value in the new list should be the original value multiplied by k; otherwise, it should remain the same. The final new list should be reversed before returning it.
task_121
Implement a function that takes a mixed alphanumeric string as input and returns the sum of all distinct numerical digits present in the string. For example, given the input 'a1b2c3d4e5', the function should return 15, as it includes the digits 1, 2, 3, 4, and 5.
task_199
Implement a rust generator function called `generate_values` that yields a specific pattern of values. The function should yield the following values in order: 'valor 4', 'valor 5', 'valor 6', 'valor 7', 'valor 8'. You should not use any external resources or classes in your implementation. The function should be efficient and should only yield values when requested. Your task is to implement this generator function.
task_154
In a rust project utilizing the Django web framework, you need to update the way primary key fields are specified in your models due to a change in the framework. The previous primary key field was represented by a string, and you need to convert this string to a new format that specifies the usage of `BigAutoField`. Write a function `convert_to_new_auto_field(old_auto_field: str) -> str` that takes an old primary key field representation as input and returns the new format for specifying the primary key field. The new format should always use `BigAutoField` from the same module as the old field. For example, if the input is 'django.db.models.AutoField', the output should be 'from django.db.models import BigAutoField'.
task_122
Write a function `calculate_median(data: List[int]) -> float` that takes a list of integers as input and computes the median value of the list. The median should be calculated by first checking if the list is sorted. If the list is not sorted, it should be sorted before computing the median. The function should not use any built-in functions for sorting or calculating the median. If the list is empty, the function should return 0.
task_8
Write a function `calculate_rectangle_properties(length: int, width: int) -> Tuple[int, int, float]` that takes the length and width of a rectangle as input and returns a tuple containing its area, perimeter, and diagonal. The length and width must be between 1 and 1000, inclusive. If the input values are outside this range, the function should raise a ValueError. The area is calculated as length * width, the perimeter as 2 * (length + width), and the diagonal using the formula sqrt(length^2 + width^2).
task_149
Write a function `convert_temp` that converts a given temperature from one scale to another. The function takes three parameters: a temperature value (float), the scale of the input temperature (a string which can be 'F' for Fahrenheit, 'C' for Celsius, or 'K' for Kelvin), and the scale to which the temperature should be converted (also a string which can be 'F', 'C', or 'K'). The function should return the converted temperature as a float. If the input temperature is invalid for the given scale, raise a ValueError. Temperature scales have the following valid ranges: Fahrenheit must be above -459.67, Celsius must be above -273.15, and Kelvin must be above 0.0.
task_54
Write a function `extract_html_info(html: str) -> Tuple[str, str, List[str]]` that takes a string representing an HTML document. The function should extract and return the page title, the content of the meta description tag, and a list of valid hyperlinks found in the page. Ignore self-closing tags and ensure that only valid URLs are included in the list of hyperlinks. If any of these elements are not found, return an appropriate default value (e.g., empty string for title and meta description, and an empty list for hyperlinks).
task_124
Write a function `extract_values(json_string: str) -> dict` that takes a JSON string as input and extracts the values associated with the keys 'key1', 'key2', and 'key3'. If a key does not exist in the JSON object, return 'Not found' for that key. The function should return a dictionary with the extracted values. If the input is not a valid JSON string, return an error message: 'Invalid JSON'.
task_109
Write a function `fibonacci_sequence(n: int) -> List[int]` that calculates the Fibonacci sequence up to the nth number. The function should return a list containing the Fibonacci numbers from 0 to n-1. You may assume that n is a positive integer.
task_145
Write a function `find_greater_value(x, y)` that takes two numerical values `x` and `y` as input parameters and returns the greater of the two values. If the values are equal, return either value.
task_5
Write a function `generate_random_string` that generates a pseudo-random string of 14 characters. The string must contain exactly 4 digits, 4 lowercase letters, 6 uppercase letters, and at least one special character. The order of the characters in the string should be randomized. The function should return the generated string.
task_191
Write a function `mock_api_call` that simulates an API call by returning a predefined response based on the provided input data. The function should take in a string `input_data`, which represents the request, and return a string response based on the following rules: If `input_data` is 'GET /user', return 'User data retrieved'. If `input_data` is 'POST /user', return 'User created'. If `input_data` is 'DELETE /user', return 'User deleted'. For any other input, return 'Unknown request'.
task_57
Write a function `odd_prime_numbers(n: int) -> List[int]` that takes an integer n and returns a list of all odd prime numbers from 1 to n, inclusively. An odd prime number is defined as a prime number that is also odd. If there are no odd prime numbers in the range, return an empty list.
task_22
Write a function in rust that takes a 2D list of integers with varying row lengths and calculates the average of all integer values in this list. The function should return the average as a float. If the input is not a 2D list of integers or if the list is empty, the function should return None.
task_160
Write a function that counts the number of occurrences of the letter 'e' in a given string, making the solution case-insensitive. The input string will have a maximum length of 100,000 characters. Implement the function `count_e(my_string: str) -> int` where `my_string` is the input string.
task_40
Write a rust function that calculates the day of the week for any given day, month, and year in the Gregorian calendar. Your function should also handle leap years and return an error message for invalid date entries such as 30th of February or 31st of April. The function should take a timezone as an argument and return the day of the week according to that timezone.
task_172
Write a rust function that computes the smallest common multiple (LCM) of three distinct integers (x, y, z). The function should be able to handle the constraints of the inputs, where 1 <= x, y, z <= 10^9. Your solution should efficiently calculate the LCM without using the naive approach of multiplying the three numbers directly. Implement the function named `find_lcm(x: int, y: int, z: int) -> int`.
task_77
You are developing an inventory management system for a game where you need to keep track of the number of available target maps in the game world. Each time a player finds a target map, the number of target maps decreases by one. Write a function `update_target_maps_count` that takes the current count of target maps as a parameter and returns the updated count after decrementing it by 1. If the count is already zero, the function should return zero, ensuring that the count does not go negative.
Function Signature: `def update_target_maps_count(amount_of_target_maps_present: int) -> int`
Example:
Input:
`update_target_maps_count(10)`
Output:
`9`
task_28
You are given a 2D list representing an image where each element is an integer representing a pixel's value. Your task is to crop a specific rectangular section of this image based on given coordinates. Implement a function `crop_image(image: List[List[int]], start_row: int, end_row: int, start_col: int, end_col: int) -> List[List[int]]` that takes the image and the coordinates for the rectangle to be cropped. The function should return a new 2D list containing only the cropped section of the image defined by the given coordinates. The coordinates will always be valid and within the bounds of the image.
task_29
You are given a class `IsotopeQuantity` that represents the quantity of a specific isotope over time. The class has the following attributes: `isotope` (a string representing the name of the isotope), `ref_date` (a datetime object representing the reference date), and a method `atoms_at(date)` that returns the number of atoms of the isotope at a specific date. Your task is to implement a function `is_equal(iq1: IsotopeQuantity, iq2: IsotopeQuantity) -> bool` that checks if two `IsotopeQuantity` instances are equal. Two instances are considered equal if they have the same isotope name and the same number of atoms at the reference date. The function should return `True` if they are equal and `False` otherwise.
task_18
You are given a country code and a phone number. Your task is to implement a function that validates whether the provided phone number adheres to the standard format of the specified country. The supported countries are 'US', 'UK', and 'Canada'. The phone number formats are as follows: US: '(+1) 123-456-7890' or '123-456-7890', UK: '(+44) 7123 456789' or '07123 456789', Canada: '(+1) 123-456-7890' or '123-456-7890'. If the country is not supported, return False.
task_88
You are given a deque data structure that allows appending elements to both ends. Implement a function `append_left_child(deque: Deque, value: str) -> None` that appends a string `value` to the left end of the deque. The function should modify the deque in-place. The deque can contain any number of string elements. After appending, you can check the leftmost element of the deque to see if it has been updated correctly. Note that the deque is represented as a doubly linked list and you can access the head of the list to check the leftmost element. Your task is to implement the function that modifies the deque as specified.
task_179
You are given a dictionary representing a configuration for an API. The dictionary contains keys 'project', 'host', and 'key', each associated with a string value. Write a function `get_api_config(config: Dict[str, str]) -> Dict[str, str]` that takes this dictionary as input and returns a new dictionary containing the same keys but with their values converted to uppercase. For example, if the input is {'project': 'my_project', 'host': 'localhost', 'key': 'secret_key'}, the output should be {'project': 'MY_PROJECT', 'host': 'LOCALHOST', 'key': 'SECRET_KEY'}.
task_34
You are given a dictionary that may or may not contain a specific key. Your task is to retrieve the value associated with that key, which could be a list or a list of lists. If the key does not exist, you should return a default value. Additionally, if the retrieved value is a list of lists, it should not exceed a specified maximum length. If it does, you should return an error. Implement a function `retrieve_list_from_dict(in_dict: dict, in_key: str, default: list, len_highest: int) -> list` that follows these rules. The function should handle the following cases: 1) If the key exists and the value is valid, return that value. 2) If the key does not exist, return the default value. 3) If the value is a list of lists and its length exceeds `len_highest`, return an error. The function should ensure that the values in the returned list match the type of elements in the default value, if available.
task_86
You are given a function that takes a number and a list of numbers. Your task is to implement a function that adds the number to the end of the list and then returns the list in reversed order. The function should not modify the input list directly. Implement the function `add_and_reverse(num: int, lead: List[int]) -> List[int]` where `num` is the number to be added and `lead` is the list of integers. The function should return a new list that is the reverse of `lead` with `num` appended to it.
task_192
You are given a list of Track objects, where each Track object has a method `toDataframe()` that returns a dictionary representation of the track with keys 'frame' and 'id'. Implement the function `tracks_to_dataframe(tracks)` that takes a list of these Track objects and returns a sorted list of dictionaries. The output list should be sorted first by 'frame' in ascending order, and then by 'id' in ascending order. If the input list is empty, return an empty list. Each Track object is guaranteed to have a valid 'frame' and 'id'.
task_83
You are given a list of column names from a dataset. Your task is to convert these column names into a format that is compatible with TensorFlow. The formatting rules are as follows: spaces, parentheses, slashes, backslashes, and question marks should be replaced with underscores, and all characters should be converted to lowercase. Implement a function that takes a list of column names and returns a new list with the modified column names based on these rules. Please write the function `format_column_names(column_names: List[str]) -> List[str]`.
task_129
You are given a list of file metadata dictionaries, where each dictionary contains details about a file including its logical name, UUID, checksum, file size, and modification date. Your task is to implement a function `get_file_info(files: List[Dict[str, Any]]) -> List[Dict[str, Any]]` that returns a list of dictionaries containing only the logical name and file size for each file that has a file size greater than 100000000 bytes (100 MB). If the input list is empty, return an empty list.
task_115
You are given a list of file names and a specific file name to check. Implement a function that takes in two parameters: a list of strings `file_list` representing the names of files and a string `target_file` representing the name of the file you want to check for in the list. The function should return True if `target_file` is present in `file_list`, and False otherwise.
task_2
You are given a list of integer lists, where each inner list represents a group of integers. Write a function that takes this list and returns a new list of integers, where each integer is the sum of the integers in the corresponding inner list. The input list will not be empty and each inner list will contain at least one integer. Your function should be able to handle lists of varying lengths. Implement the function `aggregate_sums(int_lists: List[List[int]]) -> List[int]`.
task_159
You are given a list of integers representing the ages of a group of people. Your task is to implement a function that returns the average age of the group. If the list is empty, return 0. The function should be defined as follows: `def average_age(ages: List[int]) -> float:` where `ages` is a list of integers. The average age is defined as the sum of all ages divided by the number of ages. Round the result to two decimal places.
task_82
You are given a list of integers representing the amounts of money paid by different users in a payment system. Your task is to implement a function that takes the list of payments and returns the total amount paid and the count of unique payers who contributed to this total. Each payer is represented by their unique payment amount in the list. If a payer has multiple payments, they should only be counted once towards the unique payer count. The function should be defined as follows:
```rust
def payment_summary(payments: List[int]) -> Tuple[int, int]:
```
**Input:**
- A list of integers `payments` (1 <= len(payments) <= 10^5) where each integer represents the amount paid by a user. Each amount is a positive integer (1 <= payment <= 10^6).
**Output:**
- A tuple consisting of two integers: the first integer is the total amount paid, and the second integer is the count of unique payers.
task_110
You are given a list of integers representing the capacities of various memory levels in a computing architecture. Your task is to determine if it is possible to allocate a given number of variables across these memory levels such that the capacity constraints are satisfied. Each variable must be allocated to one memory level, and no memory level can exceed its capacity. Write a function `can_allocate_memory(capacities: List[int], variables: int) -> bool` that returns `True` if the variables can be allocated within the given capacities, and `False` otherwise. The input list 'capacities' will contain positive integers representing the maximum capacity of each memory level, and 'variables' will be a positive integer representing the number of variables to allocate.
task_74
You are given a list of integers representing the net amounts of transactions in a financial dataset. Your task is to write a function called `average_change` that calculates the average change in the net amounts over the given period. The average change is defined as the sum of the differences between consecutive net amounts divided by the total number of changes. For example, given the input `net_amounts = [100, 150, 200, 175, 225]`, the average change would be calculated as follows: `(150 - 100 + 200 - 150 + 175 - 200 + 225 - 175) / 4 = 75 / 4 = 18.75`. The function should return the average change for the given list of integers.
task_167
You are given a list of integers representing the scores obtained by a player in a series of games. Your task is to implement a function that returns the maximum score from the list of scores. If the list is empty, return 0. Implement the function `max_score(scores: List[int]) -> int` where `scores` is a list of integers. The function should return the maximum score in the list if it exists, otherwise, it should return 0.
task_182
You are given a list of integers representing the scores of a game. Your task is to write a function that returns the highest score that can be achieved by removing exactly one element from the list. If there are multiple highest scores possible, return the maximum score after removing any one of the highest scores. Write a function `highest_score` that takes in a list of integers as input and returns the highest score that can be achieved by removing exactly one element from the list.
task_19
You are given a list of integers representing the scores of students in a class. Write a function `filter_and_truncate_scores(scores: List[int], threshold: int) -> List[int]` that filters out the scores below a given threshold and truncates the remaining scores to a maximum of 100. The function should return a new list containing the filtered and truncated scores. If no scores meet the criteria, return an empty list.
Function Signature: `def filter_and_truncate_scores(scores: List[int], threshold: int) -> List[int]:`
### Example:
Input: `scores = [45, 90, 102, 75, 60]`, `threshold = 70`
Output: `[90, 75, 100]`
### Constraints:
- 0 <= scores[i] <= 200
- 1 <= len(scores) <= 1000
task_170
You are given a list of integers representing the stock prices of a company over a period of time. Your task is to write a function that finds the maximum profit that can be obtained by buying and selling the stock at most once. If no profit can be made, return 0. The function should take a list of integers as input and return an integer representing the maximum profit. For example, given the stock prices [7, 1, 5, 3, 6, 4], the maximum profit that can be obtained is 5, as the stock can be bought at 1 and sold at 6. Write a function `max_profit(prices: List[int]) -> int` to solve this problem.
task_91
You are given a list of integers representing the weights of different items. Your task is to implement a function `calculate_weights_summary(weights)` that computes the total weight of all items, the average weight, and the maximum weight among the items. The function should return a dictionary containing these values. The output dictionary should have the keys 'TotalWeight', 'AverageWeight', and 'MaxWeight'. If the input list is empty, the function should return 0 for 'TotalWeight', None for 'AverageWeight', and None for 'MaxWeight'.
Example:
For input `weights = [10, 20, 30]`, the output should be:
{
'TotalWeight': 60,
'AverageWeight': 20.0,
'MaxWeight': 30
}
task_9
You are given a list of integers. Your task is to create a function that determines if the sum of the integers in the list is even or odd. You should return the string 'Even' if the sum is even and 'Odd' if the sum is odd. Write a function `sum_parity(nums: List[int]) -> str:` that takes a list of integers as input and returns the required output.
Select a cell to see row details