source stringclasses 6
values | id int64 0 111k | instruction stringlengths 167 4.39k | response stringlengths 244 6.1k |
|---|---|---|---|
python_sharegpt_23k | 6,963 | Write a Python function to generate a list of consecutive prime numbers starting from 2 up to a given number `n`. The given number `n` should be greater than 2. The function should return a list of prime numbers.
The code should start with:
```python
from typing import List
def generate_prime_numbers(n: int) -> List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_prime_numbers(n: int) -> List[int]:
"""
Generate a list of consecutive prime numbers starting from 2 up to a given number n.
Args:
n (int): The upper limit (inclusive) for gener... |
python_sharegpt_23k | 6,965 | Write a Python function to convert a binary list to an integer. The binary list can contain up to 20 elements, and each element can only be 0 or 1. The function should handle edge cases where the binary list is empty or contains invalid elements. Return the integer value of the binary list. The code should start with:
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def binary_list_to_integer(binary_list: List[int]) -> int:
"""
Converts a binary list to an integer.
Args:
binary_list (List[int]): A list of integers where each element is either 0 or 1.
... |
python_sharegpt_23k | 6,969 | Write a Python function to generate an array of size 10 filled with unique random integers from 0 to 5, sorted in ascending order. The array must contain exactly 10 elements, and each element must be unique within the range of 0 to 5. If the size of the array exceeds the number of unique elements available (which is 6 ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_unique_sorted_array(size: int) -> List[int]:
"""
Generates an array of the specified size filled with unique random integers from 0 to 5, sorted in ascending order.
Args:
... |
python_sharegpt_23k | 6,971 | Write a Python function to reverse the order of words in a given sentence while keeping the order of characters within each word intact. The function should handle punctuation marks and multiple whitespaces between words appropriately. The code should start with:
```python
def reverse_sentence(sentence: str) -> str:
``... | Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_sentence(sentence: str) -> str:
"""
Reverses the order of words in a given sentence while keeping the order of characters within each word intact.
Args:
sentence (str): The input sentence to be reversed.... |
python_sharegpt_23k | 6,983 | Write a Python function to find the smallest number in a given list of numbers. The list may contain negative numbers and decimals. The function should use only built-in Python functions to solve this problem.
The code should start with:
```python
from typing import List
def find_smallest_number(numbers: List[float])... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_smallest_number(numbers: List[float]) -> float:
"""
Find the smallest number in a given list of numbers.
Args:
numbers (List[float]): A list of numbers (integers or floats).
Re... |
python_sharegpt_23k | 6,984 | Write a Python function to generate a sorted array of a specified length with randomly generated positive integers within a given range. The array should be sorted in descending order.
The code should start with:
```python
from typing import List
import random
def generate_sorted_array(length: int, min_value: int, ma... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
def generate_sorted_array(length: int, min_value: int, max_value: int) -> List[int]:
"""
Generates a sorted array of a specified length with randomly generated positive integers within a gi... |
python_sharegpt_23k | 6,988 | Write a Python function to sort an array in descending order using the Bubble Sort algorithm. The function should not use any built-in sorting functions or methods. Only basic operations such as loops, conditional statements, and variable assignments are allowed. The input array will contain integers ranging from -1000... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort_descending(arr: List[int]) -> List[int]:
"""
Sorts the given array in descending order using the Bubble Sort algorithm.
Args:
arr (List[int]): The array of integers to be sor... |
python_sharegpt_23k | 6,990 | Write a Python function to flatten a given 2D array and print all its elements in row-wise order, without using any loops or recursion. The function should handle any size of 2D array and print the elements as a single string with elements separated by a space.
The code should start with:
```python
from typing import ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def print_2d_array_elements(arr: List[List[int]]) -> None:
"""
Flattens a given 2D array and prints all its elements in row-wise order as a single string.
Args:
arr (List[List[int]]): A 2D l... |
python_sharegpt_23k | 6,991 | Write a Python function to print all odd numbers between a given range `[start, end]` inclusive. The function should take two integers, `start` and `end`, as input and print each odd number in the range on a new line.
The code should start with:
```python
def print_odd_numbers(start: int, end: int) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def print_odd_numbers(start: int, end: int) -> None:
"""
Prints all odd numbers between the given range [start, end] inclusive.
Args:
start (int): The starting number of the range.
end (int): The ending numb... |
python_sharegpt_23k | 6,994 | Write a Python function to merge two given dictionaries into one, with the following additional requirements:
- If a key is present in both dictionaries, the corresponding values should be multiplied together instead of being overwritten.
- The merged dictionary should be sorted based on the keys in ascending order.
T... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def merge_and_multiply_dictionaries(dict1: Dict[str, int], dict2: Dict[str, int]) -> Dict[str, int]:
"""
Merge two dictionaries into one. If a key is present in both dictionaries, the corresponding value... |
python_sharegpt_23k | 6,997 | Write a Python function to count the occurrences of each character in a given input string and return the result as a dictionary where the keys are the characters and the values are their respective counts. The function should handle any input string, including those with special characters, spaces, and numbers. The co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_character_occurrences(input_string: str) -> Dict[str, int]:
"""
Counts the occurrences of each character in the given input string.
Args:
input_string (str): The input string to co... |
python_sharegpt_23k | 7,001 | Write a Python function to calculate the sum of all elements in a given matrix. The matrix is represented as a list of lists, where each inner list represents a row of the matrix. The function should iterate through each row, sum the elements of each row, and then sum all the row sums to get the total sum of the matrix... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_matrix(matrix: List[List[int]]) -> int:
"""
Calculate the sum of all elements in a given matrix.
Args:
matrix (List[List[int]]): A 2D list representing the matrix.
Returns:
... |
python_sharegpt_23k | 7,005 | Write a Python function to generate the Fibonacci sequence up to the nth number. The function should return a list containing the first n Fibonacci numbers. The code should start with:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
"""
Generate the Fibonacci sequence up to the nth number.
Args:
n (int): The number of Fibonacci numbers to generate.
Returns:
List[... |
python_sharegpt_23k | 7,007 | Write a Python function to find the second smallest number in a given list of integers without using any built-in sorting functions or libraries. The solution should have a time complexity of O(n) and use constant space. The function should return `None` if the list has fewer than two elements or if there is no distinc... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def find_second_smallest(my_list: List[int]) -> Optional[int]:
"""
Find the second smallest number in a given list of integers without using any built-in sorting functions or libraries.
Ar... |
python_sharegpt_23k | 7,017 | Write a Python function to identify the capital of a given country using a predefined dictionary of countries and their capitals. If the country is not found in the dictionary, the function should return 'Unknown'. The function should start with:
```python
def get_capital(country: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def get_capital(country: str) -> str:
"""
Returns the capital of the given country. If the country is not found, returns 'Unknown'.
Args:
country (str): The name of the country for which to find the capital.
Re... |
python_sharegpt_23k | 7,018 | Write a Python function to compute the nth Fibonacci number using memoization to improve time complexity. The function should cache previously computed Fibonacci numbers to avoid redundant calculations. The code should start with:
```python
def fibonacci_memoized(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def fibonacci_memoized(n: int) -> int:
"""
Compute the nth Fibonacci number using memoization to improve time complexity.
Args:
n (int): The position in the Fibonacci sequence to compute.
Returns:
int: ... |
python_sharegpt_23k | 7,020 | Write a Python function to calculate the sum of each row in a given 2D array and return an array containing these sums. The input array will always have at least 1 row and each row will have at least 1 element. All elements in the array will be integers.
The code should start with:
```python
from typing import List
d... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def row_sums(arr: List[List[int]]) -> List[int]:
"""
Calculate the sum of each row in a given 2D array and return an array containing these sums.
Args:
arr (List[List[int]]): A 2D array of i... |
python_sharegpt_23k | 7,024 | Write a Python function to merge two dictionaries `d1` and `d2` by adding the values of common keys. The resulting dictionary `d3` should contain all keys from both dictionaries, with values being the sum of the corresponding values from `d1` and `d2` if the key exists in both dictionaries. If a key exists only in one ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def merge_dictionaries(d1: Dict[str, int], d2: Dict[str, int]) -> Dict[str, int]:
"""
Merge two dictionaries by adding the values of common keys.
Args:
d1 (Dict[str, int]): The first diction... |
python_sharegpt_23k | 7,025 | Write a Python function to generate and return the multiplication table of a given number `num` up to a specified limit `limit`. The function should return a list of strings, where each string represents a multiplication operation in the format "num x i = result".
The code should start with:
```python
from typing impo... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_multiplication_table(num: int, limit: int) -> List[str]:
"""
Generate a multiplication table for a given number up to a specified limit.
Args:
num (int): The number for which th... |
python_sharegpt_23k | 7,030 | Write a Python function to swap the values of two variables, `a` and `b`, only if both variables are positive integers. The function should return the swapped values as a tuple `(a, b)`. If the conditions are not met, the function should return the original values as a tuple `(a, b)`.
The code should start with:
```py... | Here is the Python code to solve the given problem in the markdown block:
```python
def swap_if_positive_integers(a: int, b: int) -> tuple:
"""
Swaps the values of two variables, a and b, only if both are positive integers.
Args:
a (int): The first variable.
b (int): The second variable.
... |
python_sharegpt_23k | 7,032 | Write a Python function to generate a multiplication table for numbers from 1 to `n` (inclusive). The function should return a list of lists, where each sublist represents a row in the multiplication table. The code should start with:
```python
from typing import List
def generate_multiplication_table(n: int) -> List[... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def generate_multiplication_table(n: int) -> List[List[int]]:
"""
Generate a multiplication table for numbers from 1 to n (inclusive).
Args:
n (int): The upper limit of the range for which t... |
python_sharegpt_23k | 7,034 | Write a Python function to insert an item at a specified position in a list. The function should handle cases where the position is out of bounds by either inserting the item at the beginning or the end of the list. The code should start with:
```python
from typing import List
def insert_item_at_position(lst: List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def insert_item_at_position(lst: List[int], item: int, position: int) -> List[int]:
"""
Inserts an item at a specified position in the list. If the position is out of bounds,
the item is inserted at ... |
python_sharegpt_23k | 7,036 | Write a Python function to determine if a given array contains at least one odd prime number. An odd prime number is a number that is both odd and prime. The function should return `True` if such a number exists in the array, otherwise `False`.
The code should start with:
```python
from typing import List
def contain... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def contains_odd_prime(array: List[int]) -> bool:
"""
Determines if a given array contains at least one odd prime number.
Args:
array (List[int]): The array of integers to check.
Return... |
python_sharegpt_23k | 7,039 | Write a Python function to determine if a given number is a prime number. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The function should return `True` if the number is prime and `False` otherwise. The code should start with:
```python
def is_prime_number(num... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_prime_number(number: int) -> bool:
"""
Determine if a given number is a prime number.
Args:
number (int): The number to check for primality.
Returns:
bool: True if the number is prime, False othe... |
python_sharegpt_23k | 7,040 | Write a Python function to create a 1000x1000 matrix filled with random integers between 1 and 100 using NumPy. The function should return the generated matrix.
The code should start with:
```python
import numpy as np
def generate_random_matrix() -> np.ndarray:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
import numpy as np
def generate_random_matrix() -> np.ndarray:
"""
Generates a 1000x1000 matrix filled with random integers between 1 and 100.
Returns:
np.ndarray: A 1000x1000 matrix of random integers.
"""
... |
python_sharegpt_23k | 7,044 | Write a Python function to count the occurrences of each character in a given string and return the result as a dictionary. The function should have a time complexity of O(n), where n is the length of the string, and a space complexity of O(1) (since the number of unique characters is limited by the character set, whic... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_characters(string: str) -> dict:
"""
Counts the occurrences of each character in the given string and returns a dictionary with characters as keys and their counts as values.
Args:
string (str): The input ... |
python_sharegpt_23k | 7,045 | Write a Python function to find the most frequent character in a given string without using any built-in functions or libraries. The function should return the character that appears most frequently in the string. If there is a tie, return the character that appears first in the string.
The code should start with:
```... | Here is the Python code to solve the given problem in the markdown block:
```python
def find_most_frequent_character(s: str) -> str:
"""
Find the most frequent character in a given string without using built-in functions or libraries.
Args:
s (str): The input string to analyze.
Returns:
... |
python_sharegpt_23k | 7,046 | Write a Python function to sort a given array in descending order using only recursion. The input array will contain unique integers between 1 and 1000 inclusive. The function should not use any loops or built-in sorting functions. The code should start with:
```python
from typing import List
def sort_array_descending... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sort_array_descending(arr: List[int]) -> List[int]:
"""
Sorts the given array in descending order using only recursion.
Args:
arr (List[int]): The array of unique integers between 1 and ... |
python_sharegpt_23k | 7,047 | Write a Python function to remove all occurrences of a specific punctuation mark from a given string, while preserving the positions of other punctuation marks and characters. The function should handle any string input and any single punctuation mark as specified.
The code should start with:
```python
def remove_spec... | Here is the Python code to solve the given problem in the markdown block:
```python
def remove_specific_punctuation(input_string: str, punctuation: str) -> str:
"""
Removes all occurrences of a specific punctuation mark from the given string, while preserving the positions of other punctuation marks and charact... |
python_sharegpt_23k | 7,051 | Write a Python function to print "hi" for all pairs `(i, j)` where `i` and `j` are integers in the range `[0, 9]` and the sum of `i` and `j` is an odd number. The function should use efficient loops to minimize the number of iterations.
The code should start with:
```python
def print_hi_for_odd_sums():
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def print_hi_for_odd_sums():
"""
Prints "hi" for all pairs (i, j) where i and j are integers in the range [0, 9] and the sum of i and j is an odd number.
This function uses efficient loops to minimize the number of iteratio... |
python_sharegpt_23k | 7,052 | Write a Python function to reverse a given string without using any built-in string manipulation functions or libraries. The function should take a string as input and return the reversed string.
The code should start with:
```python
def reverse_string(s: str) -> str:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def reverse_string(s: str) -> str:
"""
Reverses the given string without using any built-in string manipulation functions or libraries.
Args:
s (str): The input string to be reversed.
Returns:
str: The ... |
python_sharegpt_23k | 7,062 | Write a Python function to compute the summation of a list of numbers, excluding any negative numbers from the calculation. The function should take a list of integers as input and return the sum of all non-negative integers in the list.
The code should start with:
```python
from typing import List
def sum_non_negati... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_non_negative(numbers: List[int]) -> int:
"""
Computes the sum of all non-negative integers in the given list.
Args:
numbers (List[int]): A list of integers.
Returns:
int... |
python_sharegpt_23k | 7,063 | Write a Python function to generate a list of tuples representing the Cartesian product of two ranges, where the outer range iterates from 0 to 4 (inclusive) and the inner range iterates from 0 to 1 (inclusive). Each tuple should contain the current iteration values of both loops.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def generate_cartesian_product() -> List[Tuple[int, int]]:
"""
Generate a list of tuples representing the Cartesian product of two ranges.
The outer range iterates from 0 to 4 (inclusive), and... |
python_sharegpt_23k | 7,064 | Implement a Python function to sort an array of integers in ascending order using the quicksort algorithm. The function should handle edge cases such as an empty array or an array with a single element correctly. The code should start with:
```python
from typing import List
def quicksort(arr: List[int]) -> List[int]:
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def quicksort(arr: List[int]) -> List[int]:
"""
Sorts an array of integers in ascending order using the quicksort algorithm.
Args:
arr (List[int]): The array of integers to be sorted.
R... |
python_sharegpt_23k | 7,067 | Write a Python function to construct a dictionary with countries and their total population, where the countries list contains duplicate values. The resulting dictionary should be sorted by population values in descending order. The code should start with:
```python
from typing import List, Dict
def construct_populati... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def construct_population_dict(countries: List[str]) -> Dict[str, int]:
"""
Constructs a dictionary with countries and their total population, sorted by population in descending order.
Args:
... |
python_sharegpt_23k | 7,070 | Write a Python function to remove duplicates from a given list while preserving the order of the elements. The list may contain integers, strings, or a combination of both. The function should handle large input arrays efficiently and should be able to handle arrays with duplicate elements at different positions.
The ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def remove_duplicates(arr: List[Union[int, str]]) -> List[Union[int, str]]:
"""
Removes duplicates from a given list while preserving the order of the elements.
Args:
arr (List[Union[... |
python_sharegpt_23k | 7,072 | Write a Python function to remove a specified element from a given tuple without using built-in functions or libraries. The function should return a new tuple with the specified element removed, maintaining the order of the remaining elements. If the target element is not present in the tuple, the function should retur... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple, Any
def remove_element_from_tuple(tuple_input: Tuple[Any], target_element: Any) -> Tuple[Any]:
"""
Removes a specified element from a given tuple and returns a new tuple with the element removed.
... |
python_sharegpt_23k | 7,079 | Write a Python function to concatenate two given lists, remove any duplicates, and return the result sorted in descending order. The function should handle lists of integers. The code should start with:
```python
from typing import List
def concatenate_and_sort_lists(list1: List[int], list2: List[int]) -> List[int]:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def concatenate_and_sort_lists(list1: List[int], list2: List[int]) -> List[int]:
"""
Concatenates two lists, removes duplicates, and returns the result sorted in descending order.
Args:
list... |
python_sharegpt_23k | 7,080 | Write a Python function to find the sum of all prime factors of a given positive integer `N` (greater than 1). The function should return the sum of these prime factors. The code should start with:
```python
def sum_of_prime_factors(N: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_prime_factors(N: int) -> int:
"""
Calculate the sum of all prime factors of a given positive integer N (greater than 1).
Args:
N (int): The positive integer for which to find the sum of prime factors.
... |
python_sharegpt_23k | 7,084 | Write a Python function to check if a given string of parentheses, brackets, and braces is balanced. A string is considered balanced if every opening bracket, brace, or parenthesis has a corresponding closing one, and they are properly nested. The function should return `True` if the string is balanced and `False` othe... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_balanced_parentheses(string: str) -> bool:
"""
Check if a given string of parentheses, brackets, and braces is balanced.
Args:
string (str): The string to check for balanced parentheses, brackets, and braces.... |
python_sharegpt_23k | 7,085 | Write a Python function that takes an integer `a` as input and returns a list containing the value of `a` incremented by 1 for each of the next 5 iterations. The function should start with:
```python
def increment_and_list(a: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def increment_and_list(a: int) -> List[int]:
"""
Returns a list containing the value of `a` incremented by 1 for each of the next 5 iterations.
Args:
a (int): The initial value to start incr... |
python_sharegpt_23k | 7,087 | Write a Python function to validate if a given value is a positive integer greater than 100. The function should return `True` if the value meets the criteria, and `False` otherwise. The code should start with:
```python
def is_valid_positive_integer(value) -> bool:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
def is_valid_positive_integer(value) -> bool:
"""
Validate if the given value is a positive integer greater than 100.
Args:
value: The value to be validated.
Returns:
bool: True if the value is a posi... |
python_sharegpt_23k | 7,090 | Write a Python function to generate and print a multiplication table for a given number `n`. The function should use nested loops to generate the table and ensure the output is neatly formatted with appropriate spacing and alignment. The function should start with:
```python
def print_multiplication_table(n: int, table... | Here is the Python code to solve the given problem in the markdown block:
```python
def print_multiplication_table(n: int, table_size: int = 10) -> None:
"""
Generates and prints a multiplication table for the given number `n`.
Args:
n (int): The number for which the multiplication table is to be g... |
python_sharegpt_23k | 7,094 | Write a Python function to compute the sum of each separate element in a given array. The function should handle arrays of integers and return the total sum of all elements. The code should start with:
```python
from typing import List
def sum_array_elements(arr: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_array_elements(arr: List[int]) -> int:
"""
Compute the sum of each separate element in a given array.
Args:
arr (List[int]): The array of integers to sum.
Returns:
int: ... |
python_sharegpt_23k | 7,095 | Write a Python function to count the number of integers in a given list that are within a specified range. The function should take three parameters: a list of integers, a lower bound, and an upper bound. It should return the count of integers in the list that fall within the inclusive range [lower_bound, upper_bound].... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def count_integers_in_range(lst: List[int], lower_bound: int, upper_bound: int) -> int:
"""
Counts the number of integers in a list that fall within the specified inclusive range.
Args:
lst ... |
python_sharegpt_23k | 7,097 | Write a Python function to determine if a given string contains all lowercase letters of the English alphabet. The function should have a time complexity of O(n), where n is the length of the string, and a space complexity of O(1).
The code should start with:
```python
def contains_all_lowercase_letters(string: str) -... | Here is the Python code to solve the given problem in the markdown block:
```python
def contains_all_lowercase_letters(string: str) -> bool:
"""
Determines if a given string contains all lowercase letters of the English alphabet.
Args:
string (str): The input string to be checked.
Returns:
... |
python_sharegpt_23k | 7,098 | Write a Python function to determine if all the elements in a given list are unique without using any additional data structures. The function should have a time complexity of O(n^2) and a space complexity of O(1). The code should start with:
```python
from typing import List
def are_elements_unique(lst: List[int]) ->... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def are_elements_unique(lst: List[int]) -> bool:
"""
Determine if all elements in the given list are unique without using any additional data structures.
Args:
lst (List[int]): The list of i... |
python_sharegpt_23k | 7,099 | Write a Python function to find the number of instances of a specific target number in a given array of integers and return the indices of the occurrences in ascending order. If the target number is not found in the array, return an empty array.
The code should start with:
```python
from typing import List
def find_t... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_target_indices(array: List[int], target: int) -> List[int]:
"""
Find the number of instances of a specific target number in a given array and return the indices of the occurrences in ascending o... |
python_sharegpt_23k | 7,100 | Write a Python function to count the frequency of each character in a given string, treating uppercase and lowercase characters as separate entities, and ignoring any special characters or punctuation marks. The function should return a dictionary where the keys are the characters and the values are their respective fr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict
def count_character_frequencies(string: str) -> Dict[str, int]:
"""
Counts the frequency of each character in the given string, treating uppercase and lowercase characters as separate entities,
and i... |
python_sharegpt_23k | 7,101 | Write a Python function that takes in two lists as input and returns a dictionary where the elements of the first list are the keys and the elements of the second list are the values. If the lengths of the two lists are not equal, the function should return an empty dictionary.
The code should start with:
```python
fr... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def create_dictionary(keys: List[str], values: List[int]) -> Dict[str, int]:
"""
Creates a dictionary from two lists where the elements of the first list are the keys and the elements of the second... |
python_sharegpt_23k | 7,102 | Write a Python function to remove even numbers and duplicates from a given array. The function should return an array containing only the odd numbers, with all duplicates removed. If the input array is empty or contains only even numbers, the function should return an empty array.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def remove_even_duplicates(arr: List[int]) -> List[int]:
"""
Removes even numbers and duplicates from the given array and returns an array of odd numbers.
Args:
arr (List[int]): The input ar... |
python_sharegpt_23k | 7,103 | Write a Python function to transpose a given 2D array. The transposed array is obtained by swapping the rows and columns of the original array. The function should handle rectangular arrays (i.e., arrays where the number of rows and columns may not be equal).
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 transpose_2d_array(arr: List[List[int]]) -> List[List[int]]:
"""
Transposes a given 2D array by swapping its rows and columns.
Args:
arr (List[List[int]]): The original 2D array to be tr... |
python_sharegpt_23k | 7,104 | Write a Python function to check whether a given element is present in an array. The array can contain integers or floating-point numbers. The function should return `True` if the element is found in the array and `False` otherwise. The function must adhere to the following constraints:
- The array can have a maximum l... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def contains_element(array: List[Union[int, float]], element: Union[int, float]) -> bool:
"""
Checks whether a given element is present in the array.
Args:
array (List[Union[int, floa... |
python_sharegpt_23k | 7,111 | Write a Python function to perform a breadth-first search (BFS) on a given graph and track the shortest path from a specified starting node to each node in the graph. The graph is represented as an adjacency list. The function should return a dictionary where the keys are nodes and the values are lists representing the... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, List, Any
from collections import deque
def bfs_shortest_path(graph: Dict[Any, List[Any]], start: Any) -> Dict[Any, List[Any]]:
"""
Perform a breadth-first search (BFS) on the given graph and track the ... |
python_sharegpt_23k | 7,112 | Write a Python function to count the number of prime numbers within a given range [start_num, end_num]. The function should handle negative input numbers and return an error message if `start_num` is greater than `end_num`. The function should only consider prime numbers greater than 1 and less than or equal to 100. Th... | Here is the Python code to solve the given problem in the markdown block:
```python
def count_primes_in_range(start_num: int, end_num: int) -> int:
"""
Count the number of prime numbers within the given range [start_num, end_num].
Args:
start_num (int): The start of the range (inclusive).
e... |
python_sharegpt_23k | 7,115 | Write a Python function to recursively flatten an array of arbitrarily nested arrays. The function should handle cases where the input array contains a mixture of integers and strings. Additionally, the function should ignore any empty arrays or arrays that only contain empty arrays. The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Union
def flatten_array(arr: List[Union[int, str, List]]) -> List[Union[int, str]]:
"""
Recursively flattens an array of arbitrarily nested arrays.
Args:
arr (List[Union[int, str, List]]): ... |
python_sharegpt_23k | 7,119 | Write a Python function to find the second largest unique value in a given array. The array may contain duplicates. If the array does not contain at least two unique values, the function should return `None`.
The code should start with:
```python
from typing import List, Optional
def second_largest_unique_value(arr: ... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def second_largest_unique_value(arr: List[int]) -> Optional[int]:
"""
Find the second largest unique value in a given array.
Args:
arr (List[int]): The array of integers from which... |
python_sharegpt_23k | 7,131 | Write a Python function that takes a list of integers as input and uses a lambda expression to filter out even numbers, returning a new list containing only the odd numbers. The function should be efficient and handle edge cases such as an empty list or a list with all even numbers.
The code should start with:
```pyth... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_odd_numbers(numbers: List[int]) -> List[int]:
"""
Filters out even numbers from the given list of integers and returns a new list containing only the odd numbers.
Args:
numbers (L... |
python_sharegpt_23k | 7,136 | Write a Python function to sort a given array of numbers from least to greatest, with even numbers appearing before odd numbers. You are not allowed to use any built-in sorting functions or libraries. The function should start with:
```python
from typing import List
def custom_sort(arr: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def custom_sort(arr: List[int]) -> List[int]:
"""
Sorts the given array of numbers from least to greatest, with even numbers appearing before odd numbers.
This function does not use any built-in sort... |
python_sharegpt_23k | 7,137 | Write a Python function to calculate the cubes of a list of positive integers and return the result as a list. The function should handle an empty list by returning an empty list. The code should start with:
```python
from typing import List
def calculate_cubes(numbers: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def calculate_cubes(numbers: List[int]) -> List[int]:
"""
Calculate the cubes of a list of positive integers and return the result as a list.
Args:
numbers (List[int]): A list of positive ... |
python_sharegpt_23k | 7,140 | Write a Python function to find the first occurrence of a prime number in a given array of integers. If no prime number is found, the function should return `None`. The function should start with:
```python
from typing import List, Optional
def find_first_prime(arr: List[int]) -> Optional[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Optional
def is_prime(n: int) -> bool:
"""
Check if a given number is prime.
Args:
n (int): The number to check for primality.
Returns:
bool: True if the number is prime, False... |
python_sharegpt_23k | 7,146 | Write a Python function to find the index of the first occurrence of a given element in a sorted array with possible duplicate elements. If the element is not found, the function should return -1. The search algorithm should have a time complexity of O(log n), where n is the size of the array.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_first_occurrence(arr: List[int], target: int) -> int:
"""
Find the index of the first occurrence of a given element in a sorted array with possible duplicate elements.
If the element is not ... |
python_sharegpt_23k | 7,147 | Write a Python function to reverse the order of elements in a given list without using any built-in functions or creating a new list. The function should modify the list in place.
The code should start with:
```python
from typing import List
def reverse_array_in_place(arr: List[int]) -> None:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_array_in_place(arr: List[int]) -> None:
"""
Reverses the order of elements in the given list in place.
Args:
arr (List[int]): The list of integers to be reversed.
Returns:
... |
python_sharegpt_23k | 7,156 | Write a Python function to generate a random string of length `n` containing only lowercase letters. The string must have at least one vowel and one consonant. The function should ensure that the generated string meets these criteria.
The code should start with:
```python
import random
import string
def generate_rand... | Here is the Python code to solve the given problem in the markdown block:
```python
import random
import string
def generate_random_string_with_vowel_and_consonant(n: int) -> str:
"""
Generate a random string of length n containing only lowercase letters.
The string must have at least one vowel and one con... |
python_sharegpt_23k | 7,159 | Write a Python function to count the number of items in a given list of positive integers between 1 and 100, and calculate the sum of all the items in the list. The list can contain up to 1000 items. The function should return both the count and the sum of the items.
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, Tuple
def count_and_sum_items(lst: List[int]) -> Tuple[int, int]:
"""
Counts the number of items in a given list of positive integers between 1 and 100,
and calculates the sum of all the items in th... |
python_sharegpt_23k | 7,161 | Write a Python function to filter a list of numbers, passing only the numbers that are greater than a given target number, and store them in a new list. The resulting list should not contain any duplicates. The function should have a time complexity of O(n) and a space complexity of O(n).
The code should start with:
`... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def filter_numbers_greater_than_target(numbers: List[int], target: int) -> List[int]:
"""
Filters a list of numbers, passing only the numbers that are greater than a given target number,
and stores t... |
python_sharegpt_23k | 7,162 | Write a Python function to convert a given string to all lowercase characters without using any built-in string manipulation functions or methods such as `toLowerCase()`, `lower()`, or any similar ones. Implement your own algorithm to achieve the conversion.
The code should start with:
```python
def to_lower_case(s: s... | Here is the Python code to solve the given problem in the markdown block:
```python
def to_lower_case(s: str) -> str:
"""
Converts a given string to all lowercase characters without using any built-in string manipulation functions.
Args:
s (str): The input string to be converted to lowercase.
... |
python_sharegpt_23k | 7,163 | Write a Python function to create an array of a specified size initialized to a given value and print the values of the array. The function should handle the case where the size is zero or negative by returning an empty array.
The code should start with:
```python
from typing import List
def initialize_and_print_arra... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def initialize_and_print_array(size: int, initial_value: int) -> List[int]:
"""
Creates an array of the specified size initialized to the given value and prints each value.
Args:
size (int):... |
python_sharegpt_23k | 7,164 | Write a Python function to compute the factorial of a given integer using recursion. The function should have a time complexity of O(n), where n is the given number. The function should not use any loops or iteration, and should only use recursion to calculate the factorial. Additionally, the function should handle edg... | Here is the Python code to solve the given problem in the markdown block:
```python
def factorial(n: int) -> int:
"""
Compute the factorial of a given non-negative integer using recursion.
Args:
n (int): The non-negative integer for which to compute the factorial.
Returns:
int: The fac... |
python_sharegpt_23k | 7,165 | Write a Python function to sort a list of numbers using the bubble sort algorithm. The function should correctly handle the sorting process and return the sorted list. The code should start with:
```python
from typing import List
def bubble_sort(nums: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort(nums: List[int]) -> List[int]:
"""
Sorts a list of integers using the bubble sort algorithm.
Args:
nums (List[int]): The list of integers to be sorted.
Returns:
... |
python_sharegpt_23k | 7,166 | Write a Python function to reverse a given array using slicing. The function should have a time complexity of O(n) and should not use any built-in functions or libraries that directly reverse the array. The code should start with:
```python
from typing import List
def reverse_array_with_slicing(arr: List[int]) -> List... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def reverse_array_with_slicing(arr: List[int]) -> List[int]:
"""
Reverses the given array using slicing.
Args:
arr (List[int]): The array to be reversed.
Returns:
List[int]: T... |
python_sharegpt_23k | 7,167 | Write a Python function to find the first index of a given string in an array of strings. If the string is not found in the array, return -1. The function should be efficient and handle edge cases such as an empty array or a string that does not exist in the array.
The code should start with:
```python
from typing imp... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_first_index(arr: List[str], string: str) -> int:
"""
Find the first index of a given string in an array of strings.
Args:
arr (List[str]): The array of strings to search through.
... |
python_sharegpt_23k | 7,168 | Write a Python function to remove duplicates from a given array of integers while maintaining the order of the first occurrence of each element. The function should have a time complexity of O(n), where n is the length of the array. The code should start with:
```python
from typing import List
def remove_duplicates_in... | Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def remove_duplicates_in_order(arr: List[int]) -> List[int]:
"""
Removes duplicates from the given array while maintaining the order of the first occurrence of each element.
Args:
arr (Lis... |
python_sharegpt_23k | 7,177 | Write a Python function to check if a prime number is present in a given list of integers. The function should return `True` if at least one prime number is found in the list, otherwise it should return `False`. The function should also check if a specified element is a prime number and include it in the check.
The co... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import math
def is_prime_number_present(lst: List[int], element: int) -> bool:
"""
Check if a prime number is present in the given list of integers or if the specified element is prime.
Args:
... |
python_sharegpt_23k | 7,181 | Write a Python function to check if a given string contains all the vowels (a, e, i, o, u) in alphabetical order. The function should return `True` if the string contains all the vowels in the correct order, and `False` otherwise. The function should be case-insensitive.
The code should start with:
```python
def conta... | Here is the Python code to solve the given problem in the markdown block:
```python
def contains_all_vowels_in_order(string: str) -> bool:
"""
Checks if a given string contains all the vowels (a, e, i, o, u) in alphabetical order.
Args:
string (str): The input string to check.
Returns:
... |
python_sharegpt_23k | 7,183 | Write a Python function to calculate the difference in minutes between two timestamps, but only if the timestamps are within the same day. If the timestamps are not within the same day, return `None`.
The function should start with:
```python
from datetime import datetime
def minutes_between_timestamps(t1: datetime, ... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def minutes_between_timestamps(t1: datetime, t2: datetime) -> int:
"""
Calculate the difference in minutes between two timestamps, but only if they are within the same day.
Args:
t1 (d... |
python_sharegpt_23k | 7,188 | Write a Python function to determine if one string (`str_1`) is contained within another string (`str_2`). The function should be case-insensitive and should ignore any leading or trailing whitespace in both strings. The function should return a boolean value indicating whether `str_1` is a substring of `str_2`.
The c... | Here is the Python code to solve the given problem in the markdown block:
```python
def is_substring(str_1: str, str_2: str) -> bool:
"""
Determines if one string is a substring of another, ignoring case and leading/trailing whitespace.
Args:
str_1 (str): The string to check if it is a substring.
... |
python_sharegpt_23k | 7,195 | Write a Python function to find the index of the first occurrence of a specific value in a given list. If the value is not found in the list, the function should return -1. The function should be efficient and handle edge cases such as an empty list or a value that does not exist in the list.
The code should start wit... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def find_first_occurrence(lst: List[int], value: int) -> int:
"""
Find the index of the first occurrence of a specific value in a given list.
Args:
lst (List[int]): The list in which to sear... |
python_sharegpt_23k | 7,196 | Write a Python function to sort a list of tuples in descending order of scores. If multiple tuples have the same score, sort them in ascending order of names. The function should take a list of tuples as input and return the sorted list.
The code should start with:
```python
from typing import List, Tuple
def sort_tu... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Tuple
def sort_tuples_by_score_and_name(tuples_list: List[Tuple[str, int]]) -> List[Tuple[str, int]]:
"""
Sorts a list of tuples by score in descending order. If multiple tuples have the same score,
... |
python_sharegpt_23k | 7,198 | Write a Python function to convert a list of strings, where each string represents a floating-point number with an optional negative sign and decimal places, into a list of integers. The function should handle any valid floating-point representation and return the corresponding integer values.
The code should start wi... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def convert_strings_to_integers(list_of_strings: List[str]) -> List[int]:
"""
Converts a list of strings, where each string represents a floating-point number, into a list of integers.
Args:
... |
python_sharegpt_23k | 7,200 | Write a Python function to create a new string from a given string by replacing each character with its opposite based on its position in the alphabet. The opposite of a character is determined by its position in the alphabet. If the character is in the first half of the alphabet (A-M for uppercase and a-m for lowercas... | Here is the Python code to solve the given problem in the markdown block:
```python
def opposite_string(input_string: str) -> str:
"""
Create a new string from the given string by replacing each character with its opposite.
The opposite of a character is determined by its position in the alphabet.
Args... |
python_sharegpt_23k | 7,202 | Write a Python function to filter out and return a list of odd numbers from a given list of integers. The function should not use any built-in functions or libraries for filtering. The code should start with:
```python
from typing import List
def filter_odd_numbers(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 filter_odd_numbers(lst: List[int]) -> List[int]:
"""
Filters out and returns a list of odd numbers from the given list of integers.
Args:
lst (List[int]): The list of integers to filter.... |
python_sharegpt_23k | 7,203 | Write a Python function to perform a depth-first search (DFS) on a given graph starting from a specified node and return the list of all nodes visited in the order they were visited. The graph is represented as an adjacency list where each key is a node and its value is a set of adjacent nodes.
The code should start w... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Dict, Set, List
def dfs_traversal(graph: Dict[str, Set[str]], start: str) -> List[str]:
"""
Perform a depth-first search (DFS) on a graph starting from a specified node.
Args:
graph (Dict[str, Se... |
python_sharegpt_23k | 7,210 | Write a Python function to increase the font size of each paragraph in a given HTML string from 12px to 24px. The function should preserve the original formatting and styling of the webpage. The solution should not use any third-party libraries or frameworks. The time complexity should be O(n), where n is the total num... | Here is the Python code to solve the given problem in the markdown block:
```python
def increase_font_size(html: str) -> str:
"""
Increases the font size of each paragraph in the given HTML string from 12px to 24px.
Args:
html (str): The HTML string containing paragraphs with font size 12px.
R... |
python_sharegpt_23k | 7,212 | Write a Python function to calculate and return the sum of the squares of numbers from 0 to a given positive integer `n`. The function should also print the square of each number from 0 to `n`.
The code should start with:
```python
def sum_of_squares(n: int) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def sum_of_squares(n: int) -> int:
"""
Calculate and return the sum of the squares of numbers from 0 to n.
Additionally, print the square of each number from 0 to n.
Args:
n (int): The upper limit (inclusive) fo... |
python_sharegpt_23k | 7,219 | Write a Python function to compute the sum of all elements in a given array of integers. The array can contain both positive and negative integers, and its length can be as large as \(10^6\). The function should be efficient and handle large inputs within a reasonable time frame.
The code should start with:
```python
... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def compute_sum(arr: List[int]) -> int:
"""
Computes the sum of all elements in a given array of integers.
Args:
arr (List[int]): The array of integers to sum.
Returns:
int: The... |
python_sharegpt_23k | 7,221 | Write a Python function to concatenate two strings after removing any leading or trailing whitespace from each string. The input strings can contain alphanumeric characters, special characters, and can have a maximum length of 100 characters each. The function should handle strings of varying lengths, including empty s... | Here is the Python code to solve the given problem in the markdown block:
```python
def concatenate_strings(str1: str, str2: str) -> str:
"""
Concatenates two strings after removing any leading or trailing whitespace from each string.
Args:
str1 (str): The first string to concatenate.
str2 ... |
python_sharegpt_23k | 7,222 | Write a Python function to find the most frequent element in a given list without using any built-in functions or libraries. The function should be efficient enough to handle large lists with millions of elements. The code should start with:
```python
def find_most_frequent_element(lst: list) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
def find_most_frequent_element(lst: list) -> int:
"""
Finds the most frequent element in a given list without using any built-in functions or libraries.
Args:
lst (list): The list of integers from which to find the ... |
python_sharegpt_23k | 7,223 | Write a Python function to sort an array of integers in ascending and descending order without using any built-in sorting functions or libraries. The function should implement the Bubble Sort algorithm for both sorting orders.
The code should start with:
```python
from typing import List
def bubble_sort(arr: List[int... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort(arr: List[int], ascending: bool = True) -> List[int]:
"""
Sorts an array of integers in ascending or descending order using the Bubble Sort algorithm.
Args:
arr (List[int]): ... |
python_sharegpt_23k | 7,225 | Write a Python function to convert an RGB color to its hexadecimal representation without using any built-in functions or libraries specifically designed for color conversions. The function should handle RGB values within the valid range (0-255) and return the hexadecimal color code as a string prefixed with a `#`.
Th... | Here is the Python code to solve the given problem in the markdown block:
```python
def rgb_to_hex(red: int, green: int, blue: int) -> str:
"""
Converts an RGB color to its hexadecimal representation.
Args:
red (int): The red component of the RGB color, in the range 0-255.
green (int): The ... |
python_sharegpt_23k | 7,228 | Write a Python function to find the longest string from a given list of strings that contains at least one uppercase letter and one lowercase letter. If there are multiple strings with the same maximum length, return the first one encountered. If no such string exists, return an empty string.
The code should start wit... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def longest_string_with_letters(strings: List[str]) -> str:
"""
Find the longest string from a list that contains at least one uppercase letter and one lowercase letter.
Args:
strings (List[... |
python_sharegpt_23k | 7,230 | Write a Python function to sort a list of integers in ascending order using the bubble sort algorithm. The function should not modify the original list but return a new sorted list. The code should start with:
```python
from typing import List
def bubble_sort(nums: List[int]) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def bubble_sort(nums: List[int]) -> List[int]:
"""
Sorts a list of integers in ascending order using the bubble sort algorithm.
Args:
nums (List[int]): The list of integers to be sorted.
... |
python_sharegpt_23k | 7,233 | Write a Python function to generate an array of the first `n` Fibonacci numbers without using recursion. The function should start with:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
```
| Here is the Python code to solve the given problem in the markdown block:
:
```python
from typing import List
def generate_fibonacci(n: int) -> List[int]:
"""
Generate an array of the first n Fibonacci numbers.
Args:
n (int): The number of Fibonacci numbers to generate.
Returns:
List[... |
python_sharegpt_23k | 7,235 | Write a Python function to determine if all elements in a given array are similarly oriented, meaning either all elements are positive, all are negative, or all are zero. The function should handle cases where the array is empty or contains only one element. The function should have a time complexity of O(n), where n i... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def is_similarly_oriented(arr: List[int]) -> bool:
"""
Determines if all elements in the given array are similarly oriented.
Args:
arr (List[int]): The array of integers to check.
Retur... |
python_sharegpt_23k | 7,241 | Write a Python function to reverse an array in place without using any extra space. The function should have a time complexity of O(n), where n is the size of the array. The function should modify the original array and not use any built-in reverse functions or create a new array.
The code should start with:
```python... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def reverse_array_in_place(arr: List[int]) -> None:
"""
Reverses the given array in place without using any extra space.
Args:
arr (List[int]): The array to be reversed.
Returns:
... |
python_sharegpt_23k | 7,248 | Write a Python function to convert a timestamp from epoch time to human-readable time. The timestamp is provided as a string in the format "yyyy-mm-dd HH:MM:SS". The function should return the human-readable time in the format "Month dd, yyyy HH:MM:SS AM/PM".
The code should start with:
```python
from datetime import ... | Here is the Python code to solve the given problem in the markdown block:
```python
from datetime import datetime
def convert_timestamp_to_human_readable(timestamp: str) -> str:
"""
Converts a timestamp from epoch time to a human-readable format.
Args:
timestamp (str): The timestamp in the format ... |
python_sharegpt_23k | 7,253 | Write a Python function to generate a random string of a given length. The string should consist of random uppercase and lowercase letters. The function should handle the case where the length is zero by returning an empty string. The code should start with:
```python
from typing import List
import random
import string... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
import random
import string
def generate_random_string(length: int) -> str:
"""
Generates a random string of the given length consisting of uppercase and lowercase letters.
Args:
length (int... |
python_sharegpt_23k | 7,257 | Write a Python function to loop through a list of dictionaries and print the value of the "name" property for each dictionary. If the "name" property is missing in any dictionary, print "Unknown" instead. The function should start with:
```python
from typing import List, Dict
def print_names(data: List[Dict[str, any]]... | Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List, Dict
def print_names(data: List[Dict[str, any]]) -> None:
"""
Loop through a list of dictionaries and print the value of the "name" property.
If the "name" property is missing in any dictionary, pri... |
python_sharegpt_23k | 7,258 | Write a Python function to calculate the sum of all even numbers in a given list of integers using a while loop. The function should iterate through the list and sum only the even numbers. The code should start with:
```python
from typing import List
def sum_of_even_numbers_while(lst: List[int]) -> int:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import List
def sum_of_even_numbers_while(lst: List[int]) -> int:
"""
Calculate the sum of all even numbers in a given list of integers using a while loop.
Args:
lst (List[int]): The list of integers to... |
python_sharegpt_23k | 7,260 | Write a Python function to modify a given tuple by changing the second element to the sum of the first and third elements. The function should return the modified tuple. The code should start with:
```python
from typing import Tuple
def modify_tuple(my_tuple: Tuple[int, int, int]) -> Tuple[int, int, int]:
```
| Here is the Python code to solve the given problem in the markdown block:
```python
from typing import Tuple
def modify_tuple(my_tuple: Tuple[int, int, int]) -> Tuple[int, int, int]:
"""
Modify the given tuple by changing the second element to the sum of the first and third elements.
Args:
my_tupl... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.