[output] | SELECT * FROM Customers WHERE country = 'United States'; [instruction] | Write a query in SQL to find all records from the "Customers" table where the country is the United States. [input] |
[output] | CREATE OR REPLACE PROCEDURE getLastName(id IN Integer) BEGIN SELECT Last_Name INTO Last_Name FROM Employees WHERE Employees.ID = id; END; [instruction] | Write a procedure in PL/SQL that returns the last name of an employee if the ID of the employee is provided as an argument. [input] | id : Integer
[output] | $.ajax({url: "example.com", method: "GET"}); [instruction] | Write a one-sentence JavaScript statement to make an AJAX call to a website. [input] |
[output] | O(n^2) represents a time complexity in which the execution time of an algorithm increases in proportion to the square of the input size. [instruction] | Describe what O(n^2) represents in terms of complexity. [input] |
[output] | A <- matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9), nrow = 3, ncol = 3) B <- A[1,] [instruction] | Translate the following MATLAB code snippet into R. [input] | A = [1 2 3; 4 5 6; 7 8 9]; B = A(1, :)
[output] | <div id="main" class="container"></div> [instruction] | Create an HTML div with an ID of "main" and a class of "container". [input] |
[output] | public static int findMax(int[] sequence) { int maxVal = Integer.MIN_VALUE; for (int val : sequence) { if (val > maxVal) { maxVal = val; } } return maxVal; } [instruction] | Construct a function in Java that takes a sequence of numbers and finds the maximum value in the sequence. [input] |
[output] | try: f = open("myfile.txt") text = f.read() except IOError: print("Error: Could not open file") finally: f.close() [instruction] | Rewrite the following Python code to include proper exception handling. [input] | f = open("myfile.txt") text = f.read()
[output] | SELECT SUM(Salary) FROM Employees WHERE Department = 'DEPARTMENT-NAME'; [instruction] | Construct a query in MySQL to calculate the total salary of all employees in a given department. [input] |
[output] | def sum_primes(n): # Initialize sum to 0 sum_prime = 0 # Iterate through all numbers from 0 to n for num in range(2, n+1): is_prime = True # Check whether the number is prime for div in range(2, num): if num % div == 0: is [instruction] | Suggest an algorithm to compute the sum of all prime numbers from 2 to n. [input] |
[output] | # Get the number of distinct elements in a list numbers_list = [1, 2, 3, 2, 4, 5, 1] # Create a set from the list distinct_elements = set(numbers_list) # Return the number of distinct elements return len(distinct_elements) [instruction] | Given a list of numbers, suggest code that returns the number of distinct elements in the list. [input] | numbers_list = [1, 2, 3, 2, 4, 5, 1]
[output] | # The best data structure to store a small dictionary of words and their meanings is a hash table (dictionary/dict). # A hash table is an efficient data structure that uses key-value pairs to store and retrieve data quickly. # It performs well in cases where there is a need to search, add and delet [instruction] | Suggest the best data structure to store a small dictionary of words and their meanings. [input] |
[output] | # Method to validate whether an input string is a valid JSON document def is_valid_json(input_string): # Try to parse the given string with the json library try: json.loads(input_string) return True # If there is an error while parsing the string, it is not a valid JSON d [instruction] | Suggest a method to validate whether an input string is a valid JSON document or not. [input] |
[output] | # Combine two lists of strings without duplicates list1 = ["one", "two", "three"] list2 = ["two", "four", "five"] # Create a new set that only contains distinct elements distinct_elements = set(list1 + list2) # Convert the set back to a list combined_list = list(distinct_elements) [instruction] | Suggest a code that combines two lists of strings without duplicates. [input] | list1 = ["one", "two", "three"] list2 = ["two", "four", "five"]
[output] | # Sort a list containing numbers and a list containing strings together, in ascending order num_list = [2, 4, 6, 1] string_list = ['zanzibar', 'banana', 'apple'] # Combine lists combined_list = num_list + string_list # Sort the list combined_list.sort() # Print the result print(combined_list) [instruction] | Sort a list containing numbers and a list containing strings together, in ascending order. [input] | num_list = [2, 4, 6, 1] string_list = ['zanzibar', 'banana', 'apple']
[output] | # Get the age of a person given their year of birth from datetime import date def get_age(born_year): # Get current year today_year = date.today().year # Compute the age age = today_year - born_year # Return the result return age [instruction] | Write a code to get the age of a person given their year of birth. [input] | born_year = 2003
[output] | # Suggest a code that takes a two-dimensional array as input and flattens it def flatten_array(arr): # Initialize the result array result_arr = [] # Iterate the input array for subarr in arr: # Iterate each sub-array and add each element to the result array for elem [instruction] | Suggest a code that takes a two-dimensional array as input and flattens it. [input] | arr = [[1,2],[3,4],[5,6]]
[output] | H_ll_ W_rld! [instruction] | Replace the vowel characters in a given string with underscores. [input] | Hello World!
[output] | def multiply_list_by_five(arr): result = [] for num in arr: result.append(num * 5) return result [instruction] | You have been provided with a list of integers. Write a function that multiplies each number in the list by 5. [input] | [1, 20, 0, 5, 2]
[output] | \S+@gmail\.com$ [instruction] | Create a regular expression that matches the email address with the domain gmail.com [input] |
[output] | def count_frequency_of_words(string, word_list): frequency_dict = {} string_words = string.split() for word in word_list: count = 0 for s_word in string_words: if s_word.lower() == word.lower(): count += 1 frequency_dict[word] = count [instruction] | Given a string and a list of words, count the frequency of each word in the string. [input] | String = "This is a test string to check the frequency of words" Word List = ["this", "is", "test", "string"]
[output] | def extract_capital_words(string_list): capital_words = [] for word in string_list: if word[0].isupper(): capital_words.append(word) return capital_words [instruction] | Given a list of strings, write a function which will return only strings which start with an uppercase letter. [input] | String List = ["hello", "World", "foo", "bar"]
[output] | SELECT name, SUM(salary) FROM employees GROUP BY name; [instruction] | Write a SQL query to fetch the name of employees and the sum of their salaries from the database. [input] |
[output] | \(?\d{3}\)?-?\s?\d{3}-?\s?\d{4} [instruction] | Create a regular expression that will match all telephone numbers. [input] |
[output] | def largest_sum_of_consecutive_ints(arr): largest_sum = 0 for i in range(len(arr)): if i < len(arr)-1: current_sum = arr[i] + arr[i+1] largest_sum = max(largest_sum, current_sum) return largest_sum [instruction] | Given a list of integers, write a function that will return the largest sum of any two consecutive integers in the list. [input] | [7, 2, 5, 3]
[output] | def remove_non_alphanumeric_chars(input): output = "" for char in input: if char.isalnum(): output += char return output [instruction] | Given an input string, write a function that will remove all non-alphanumeric characters. [input] | Hello World!
[output] | def find_elements_larger_than_neighbours(arr): result = [] for index, value in enumerate(arr): if index > 0 and index < len(arr)-1 and value > arr[index-1] and value > arr[index+1]: result.append(value) return result [instruction] | You need to write a program that finds all elements in a given array which are larger than their immediate neighbours. [input] | [3, 5, 1, 6, 8, 4]
[output] | function factorial(n) { if (n == 0) { return 1; } return n * factorial(n - 1); } [instruction] | Create a JavaScript function which takes a number as an argument and calculates the factorial of that number. [input] |
[output] | my_list = [1,2,3,4] for i in range(len(my_list)-1,-1,-1): print(my_list[i]) [instruction] | Create code that will print the elements of a list in reverse order. [input] | my_list = [1,2,3,4]
[output] | <!doctype html> <html> <head> <title>My website</title> </head> <body> <div class="container"> <h1>Welcome to my website!</h1> </div> <script> console.log('Welcome to my website!'); </script> </body> </html> [instruction] | Write a web page using HTML, CSS, and JavaScript that displays the following text: "Welcome to my website!". [input] |