[output] | import pandas as pd data = {'product':['Burger', 'Fries'], 'price':[6, 2]} df = pd.DataFrame(data) print(df) [instruction] | Generate a data frame with two columns: 'product' and 'price' [input] | product1: Burger price1: $6 product2: Fries price2: $2
[output] | Independent variable: x Dependent variable: y [instruction] | Identify the dependent and independent variables in the following equation [input] | y=x^2+5
[output] | The greatest common divisor of 36 and 24 is 12. [instruction] | Calculate the greatest common divisor of 36 and 24 [input] |
[output] | class Stack: def __init__(self): self.stack = [] def push(self, item): self.stack.append(item) def pop(self): self.stack.pop() def peek(self): return self.stack[-1] def is_empty(self): return not self.stack [instruction] | Design a stack class for a language of your choice [input] |
[output] | long_words = [word for word in ["apple", "banana", "carrot"] if len(word) > 5] [instruction] | Create a new list of strings of length greater than 5 from another list [input] | ["apple", "banana", "carrot"]
[output] | Letter frequency: L: 1 O: 2 R: 2 E: 2 M: 2 I: 2 P: 2 S: 2 U: 2 D: 1 A: 2 C: 2 T: 2 G: 1 [instruction] | Output the letter frequency from a text [input] | Lorem ipsum dolor sit amet, consectetur adipiscing elit.
[output] | import numpy as np df_array = np.array(df) [instruction] | Take the following pandas DataFrame, and convert it to a NumPy array. [input] | import pandas as pd df = pd.DataFrame([[1,2,3], [4,5,6], [7,8,9]])
[output] | value = env[variable] [instruction] | Find the value of a variable in a given environment. [input] | env={'key1': 1, 'key2': 2} variable="key2"
[output] | def quick_sort(A): quick_sort_helper(A, 0, len(A) - 1) def quick_sort_helper(A, start, end): if start < end: p_index = partition_list(A, start, end) quick_sort_helper(A, start, p_index - 1) quick_sort_helper(A, p_index + 1, end) def partition_list(A, start, end): [instruction] | Implement a quick sort algorithm for a given array list. [input] |
[output] | def generateDivisors(n): divisors = [] for i in range(1, n + 1): if n % i == 0: divisors.append(i) return divisors [instruction] | Generate a list of all the divisors of a given number. [input] |
[output] | def subsetsum(arr, target): n = len(arr) dp = [[False for x in range(target + 1)] for y in range(n + 1)] dp[0][0] = True for i in range(1, n+1): for j in range(target + 1): dp[i][j] = dp[i-1][j] or (arr[i-1] <= j and dp[i-1][j - arr[i-1]]) return dp[n][target [instruction] | Given a list of numbers and a target, write an algorithm to determine if the list contains a subset that sums up to the target. [input] |
[output] | CREATE TABLE movies ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255), genre VARCHAR(255), release_year INT, rating DECIMAL(2,1) ); [instruction] | Write an SQL statement for creating a table called "movies". [input] |
[output] | answer = sum(1:10) [instruction] | Formulate a MATLAB expression for calculating the sum of the first 10 natural numbers. [input] |
[output] | SELECT title FROM movies WHERE release_year = 2000; [instruction] | Execute a valid query using PostgreSQL for finding the title of all movies released in the year 2000. [input] |
[output] | int num = 15; if(num % 2 == 0) { System.out.println("Even"); } else { System.out.println("Odd"); } [instruction] | Construct an if-else block in Java to determine if the number 15 is an even number or an odd number. [input] | Integer: 15
[output] | #!/bin/bash #array elements arr=(2 5 1 8 4) #Sorting the array in ascending order for((i=0;i<4;i++)) do for((j=0;j<4-i;j++)) do if [ ${arr[j]} -gt ${arr[$((j+1))]} ] then # swap temp=${arr[j]} arr[$j]=${arr[$((j+1))]} arr[$((j+1)) [instruction] | Design a shell script for sorting the elements of a given array [2, 5, 1, 8, 4]. [input] | Array elements: [2, 5, 1, 8, 4]
[output] | func addTwoNumbers(number1: Int, number2: Int) -> Int { let result = number1 + number2 return result } let input1 = 5 let input2 = 10 let result = addTwoNumbers(number1: input1, number2: input2) print("The result of addition is \(result)") [instruction] | Generate a Swift program for adding two numbers given as input. [input] | Input 1: 5 Input 2: 10
[output] | int num = 0; while(num <= 10) { printf("%d ", num); num += 2; } [instruction] | Construct a while loop in C for printing even numbers from 0 to 10. [input] |
[output] | body { background-color: yellow; } [instruction] | Create a CSS block for changing the background color of a webpage to yellow. [input] |
[output] | #include <stdio.h> int factorial(int n) { int result = 1; for (int i = 1; i <= n; i++) { result *= i; } return result; } int main() { int input = 5; int result = factorial(input); printf("The factorial of %d is %d", input, result); return 0; } [instruction] | Write an Objective-C program for printing the factorial of a number 5. [input] | Integer number: 5
[output] | def max_difference(arr): difference = 0 for i in range(len(arr)): for j in range(i + 1, len(arr)): if arr[j] - arr[i] > difference: difference = arr[j] - arr[i] return difference [instruction] | Create a function in Python that will return the maximum difference between any two numbers present in an array. [input] |
[output] | def secondLargest(arr): first = 0 second = 0 for i in range(len(arr)): if arr[i] > first: second, first = first, arr[i] elif (arr[i] > second and arr[i] < first): second = arr[i] return second [instruction] | An array of integers is given, write a function to print the second largest element of the array. [input] |
[output] | public static List<Integer> getElementsGreaterThan(int[] array, int number) { List<Integer> result = new ArrayList<>(); for (int element : array) { if (element > number) { result.add(element); } } return result; } [instruction] | Write a code in Java that will get all the elements from an array that are greater than the given number. [input] |
[output] | \bhello\b [instruction] | Create a Regex expression that will match strings that contain the word "hello". [input] |
[output] | def reverseString(s): return s[::-1] [instruction] | Given the following string, provide a function to reverse it. [input] | "Hello World!"
[output] | SELECT name, age, current_salary FROM employees WHERE age > 30 [instruction] | Write a SQL query that will get the name, age, and current salary of all employees who are older than 30. [input] |
[output] | def reverseWords(s): words = s.split(" ") words.reverse() return " ".join(words) [instruction] | Write a code in Python that will take a string as input and return it with the words in reverse order. [input] |
[output] | string = "abcedfghijx" for idx, char in enumerate(string): if char == 'x': print(f"The loop index was {idx} when the letter 'x' was found.") break [instruction] | Construct a loop through this string of characters to check for the letter ‘x’. Report what the loop index was when the letter ‘x’ was found. [input] | string = "abcedfghijx"
[output] | list_nums = [i for i in range(10, 21)] [instruction] | Write a code to generate a list of numbers from 10 to 20 (inclusive). [input] |
[output] | def tuple_to_dict(tup): return {tup[i] : tup[i+1] for i in range(0, len(tup), 2)} [instruction] | Suggest a function to convert a given tuple of strings into a dictionary. [input] |