[output] | def array_to_floats(string_arr): # Create an array to store the float values float_arr = [] # Iterate over the given array and convert to float for s in string_arr: float_arr.append(float(s)) # Return the new array return float_arr string_arr=['1.1', '2.3', '3.4'] re [instruction] | Write a function to convert an array of strings to an array of floats. [input] | string_arr=['1.1', '2.3', '3.4']
[output] | import random def generate_pin(): """ This function generates a random PIN of 8 characters. Parameters ---------- None Returns ------- pin : str The generated PIN """ characters= "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" pin = "" for _ in rang [instruction] | Generate a random PIN of 8 characters. [input] |
[output] | def sort_list(n_list): """ Sort a given list of numbers in ascending order. Parameters ---------- n_list: list The list of numbers to sort Returns ------- sorted_list : list The sorted list """ sorted_list = sorted(n_list) return sorted_l [instruction] | Sort a list of numbers so that the lowest number appears first. [input] | n_list = [3, 9, 1, 4, 5]
[output] | def compute_combination(n, r): """ Compute the number of ways for a host to select 'r' items from a list of 'n' options. Parameters ---------- n : int The total number of items r : int The number of items to select Returns ------- num : int [instruction] | Compute the number of ways for a host to select 3 items from a list of 8 options. [input] |
[output] | def search_list(string_list, search_term): """ Search a list for a given string and return its index. Parameters ---------- string_list : list The list to search search_term : str The string to search for Returns ------- index : int The i [instruction] | Search a list to find a string and return its index. [input] | string_list = ["apple", "banana", "orange"] search_term = "orange"
[output] | def extract_name(string): """ Parse a given string and extract the name from it. Parameters ---------- string : str The string to parse Returns ------- name : str The extracted name """ # Split the string by words words = string.split() [instruction] | Parse a given string and extract the name from it. [input] | string = "Hi! My name is John Smith"
[output] | import matplotlib.pyplot as plt def create_histogram(dataset): """ Create a histogram chart of the given data. Parameters ---------- dataset : list The data to plot on the chart Returns ------- None """ plt.hist(dataset, bins=7, facecolor="blue", al [instruction] | Create a histogram chart of the given data. [input] | dataset = [2, 3, 5, 6, 7, 4]
[output] | from nltk.corpus import stopwords import string def preprocess_document(document): """ Preprocess a given document, removing stopwords and punctuations. Parameters ---------- document : str The document to preprocess Returns ------- clean_word_list : list [instruction] | Preprocess a given document, removing stopwords and punctuations. [input] | document = "Hello! This is a test document for preprocessing"
[output] | def remove_duplicates(arr): result = [] for el in arr: if el not in result: result.append(el) return result [instruction] | Design an algorithm to eliminate duplicate elements in a given array. [input] | Array: [1, 5, 1, -2, 5]
[output] | String: ab de [instruction] | Replace each occurrence of the given character in a string with a space. [input] | String: abcde Character: c
[output] | tasks = ["cook breakfast", "run errand", "pick up kids", "feed the dog"] [instruction] | You are given a string of tasks. Split the string into a list of tasks. [input] | Tasks = "cook breakfast;run errand;pick up kids; feed the dog"
[output] | def sqrt(N): guess = N/2 while abs(guess*guess - N) >= 0.001: guess = 0.5 * (guess + N/guess) return guess [instruction] | Given a number N find the square root of N. [input] |
[output] | def uniq_array(nums): distinct_arr = [] for num in nums: if num not in distinct_arr: distinct_arr.append(num) return distinct_arr [instruction] | Given an array of integers, remove all the duplicated elements from the array and return the distinct array. [input] | nums=[3, 4, 5, 5, 6, 6, 6, 7]
[output] | def word_count(words): count = 0 for word in words.split(): count+=1 return count [instruction] | You are given a string of words. Count how many words the string contains. [input] | words = "This is a testing string"
[output] | def char_count(text): count = 0 for char in text: count += 1 return count [instruction] | Given a string of text, find the total number of characters in the string. [input] | text = "You have to do it"
[output] | def max_sum_subsequence(nums): max_sum = 0 curr_sum = 0 for num in nums: curr_sum = max(num + curr_sum, 0) max_sum = max(curr_sum, max_sum) return max_sum [instruction] | You are given a list of numbers. Find the maximum sum of any subsequence in the list. [input] |
[output] | def count_lowercase(string): count = 0 for char in string: if char.islower(): count += 1 return count [instruction] | You are given a string. Count the total number of lowercase letters in the string. [input] |
[output] | def multiplyArray(arr): result = 1 for x in arr: result = result * x return result [instruction] | Write a function that takes an array of integers and multiplies them together. [input] | arr = [3, 5, 4]
[output] | This coding question is asking you to write a Python function to check whether a given number is prime or not. The function should take an integer as an argument and return a boolean indicating if the number is prime or not. [instruction] | What is this coding question asking you to do? [input] | Write a Python function to check whether a number is prime or not
[output] | str1 = "python" str2 = " programming" print(str1 + str2) [instruction] | Edit the code such that it prints the same output. [input] | str1 = "python " str2 = "programming" print(str1 + str2)
[output] | def main(): temp = 22 if temp > 30: print('It is a hot day') elif temp < 10: print('It is a cold day') else: print('It is a lovely day') main() [instruction] | Fill in the blanks in the following code to make it an executable program. [input] | def main(): temp = _____ if _____: print('It is a hot day') elif _____: print('It is a cold day') else: print('It is a lovely day') main()
[output] | The advantages of using the Linear Regression algorithm with Stochastic Gradient Descent (SGD) in Python include: 1. It is relatively fast to train, as it only has to go through each sample in the dataset once in order to generate the coefficients. 2. It requires small datasets and low complexity m [instruction] | Explain the advantages of using the following linear regression algorithm in Python. [input] | Linear Regression using Stochastic Gradient Descent
[output] | sample_list = ["Apples", "Oranges", "Pears"] [instruction] | Remove the element with the value “Carrots” from the given list. [input] | sample_list = ["Apples", "Oranges", "Pears", "Carrots"]
[output] | If x = 6, the returned value is 12. [instruction] | Determine the returned value of the following function. [input] | def my_fun(x): if x > 5: return x * 2 else: return x * 3
[output] | A variable is a named container for storing data values. Variables are usually used in programming to store and access data in a program. It is important to use a descriptive name for the variable, as it can be used to access the data within it. [instruction] | Define the term variable. [input] |
[output] | The sorting algorithms supported in Python include bubble sort, insertion sort, selection sort, merge sort, quick sort, and heap sort. [instruction] | List out all the sorting algorithms supported in Python. [input] |
[output] | def remove_duplicates(array): new_array = [] for number in array: if number not in new_array: new_array.append(number) return new_array print(remove_duplicates([5,5,5,10,10,15])) [instruction] | Create a function that removes duplicates from an array and returns an array of the unique values. [input] | array = [5,5,5,10,10,15]
[output] | def permute(string): # base case if len(string) == 1: return [string] results = set() # iterate through each character in the string for i in range(len(string)): # select the ith character char = string[i] # generate all the permutations from the remaining characters [instruction] | Find all the possible permutations in a string without using any built-in functions. [input] | string = "ABC"
[output] | def detect_overlapping_dates(dates_list): overlaps = set() for i in range(len(dates_list)-1): for j in range(i+1, len(dates_list)): date1_start_year, date1_start_month, date1_start_day, date1_end_year, date1_end_month, date1_end_day = dates_list[i] date2_start_year, date2_start [instruction] | Create a function which detects overlapping dates from a given list. [input] | dates_list = [ (2018,1,1,2018,3,1), (2018,12,1,2018,9,30), (2018,2,15,2018,5,10) ]
[output] | def remove_negative_numbers(numbers_list): result_list = [] for number in numbers_list: if number >= 0: result_list.append(number) return result_list numbers_list = [-2,-3,4,5,-6,7] print(remove_negative_numbers(numbers_list)) [instruction] | Given a list of integers, remove all negative numbers. [input] | numbers_list = [-2,-3,4,5,-6,7]