[output] | a = 5 [instruction] | Create a Python variable a with value 5. [input] |
[output] | arr = list(set(arr)) # [1, 2, 3, 4, 5, 6] [instruction] | Given a variable arr containing integers, write python code to remove all duplicate elements from the array and return the new array. [input] | arr = [1, 2, 2, 3, 4, 4, 4, 5, 6, 6]
[output] | for element in reversed(my_list): print(element) [instruction] | In Python, how could you print a list from the last element to the first element? [input] |
[output] | d = {i: i*i for i in range(1, 11)} # {1:1, 2:4, etc.} [instruction] | Create a dictionary in Python whose keys are the integers from 1 to 10 and whose values are the squares of the keys. [input] |
[output] | def find_missing_num(arr): missing = 0 for i in range(arr[0], arr[-1] + 1): if i not in arr: missing = i return missing # 4 [instruction] | Write an algorithm to find the missing number in an array of n consecutive integers in Python. [input] | arr = [1, 2, 3, 5, 6, 7, 8]
[output] | string1.count(string2) # 1 [instruction] | Count the number of occurrences of a given string in another string in Python. [input] | string1 = 'A quick brown fox jumps over the lazy dog.' string2 = 'dog'
[output] | new_lst = [x for x in lst if len(x) > 4] # ['apple', 'banana'] [instruction] | Given a list of strings, write a program to return a new list of all strings which have length greater than 4 in Python. [input] | lst = ['cat', 'dog', 'apple', 'banana']
[output] | He was very contentious throughout the meeting. [instruction] | Replace the underlined phrase with a single word that means the same thing: He was very argumentative throughout the meeting. [input] |
[output] | public int calculateSum(int x, int y) { return x + y; } [instruction] | Create a method with the following signature: int calculateSum(int x,int y). [input] |
[output] | Let's attempt to solve this problem. [instruction] | Rewrite the following sentence so that it has a different meaning: We should try and solve this problem. [input] |
[output] | Java, Python and JavaScript. [instruction] | Name three popular programming languages. [input] |
[output] | The user interface should include a search bar to search for books, a list of books with details such as title, author, year published, and a button to select a book and checkout. Additionally, it should include a navigation header with various sections such as 'My Books', 'Favorites', 'Recommendati [instruction] | Design a user interface for a book library application. [input] |
[output] | int sum = 0; for (int i = 2; i < 10; i += 2) { sum += i; } Console.WriteLine("The sum of the first 5 positive even numbers is: " + sum); [instruction] | Generate a for loop for summing up the first 5 positive even numbers. [input] |
[output] | int[] array = {7, 14, 23, 27, 33}; int sum = 0; int i = 0; for (; i < array.Length; ++i) { sum += array[i]; } [instruction] | Read the following code and suggest an optimization. [input] | int[] array = {7, 14, 23, 27, 33}; int sum = 0; foreach (int value in array) { sum += value; }
[output] | for letter in range(97, 123): print(chr(letter)) [instruction] | Create a for loop for printing all the alphabets in the lowercase. [input] |
[output] | The Merge Sort algorithm is suitable for a large, unsorted integer array. It is a divide and conquer algorithm, which divides the array into two halves, recursively sorts them, and then merges them together. It has a time complexity of O(n log n). [instruction] | Suggest a sorting algorithm that is suitable for a large, unsorted integer array. [input] |
[output] | int[] arr = {1, 2, 3, 4, 5}; int result = 0; for (int i = 0; i < arr.Length; i++) { result += arr[i]; for (int j = i + 1; j < arr.Length; j++) { if (arr[i] % arr[j] == 0) { result += arr[j]; } } } [instruction] | Edit the given code snippet and make it run in O(N) time complexity. [input] | int[] arr = {1, 2, 3, 4, 5}; int result = 0; for (int i = 0; i < arr.Length; i++) { for (int j = 0; j < arr.Length; j++) { if (arr[i] % arr[j] == 0) { result += arr[i]; } } }
[output] | public class Student { private String name; private Date dob; private int grade; public Student(String name, Date dob, int grade) { this.name = name; this.dob = dob; this.grade = grade; } // Additional methods/Getters and Setters } [instruction] | Create a class in Java for a student and define variables for name, date of birth and grade. [input] |
[output] | i = 2 sum = 0 while i < 10: sum += i i += 2 print("The sum of first 5 even numbers is: ", sum) [instruction] | Generate a while loop in python to find out the sum of first 5 even numbers. [input] |
[output] | console.log("Hello World"); [instruction] | You need to generate a Javascript program that prints "Hello World". [input] |
[output] | public static int longestIncreasingSubsequence(int[] arr) { int[] dp = new int[arr.length]; int maxLength = 1; dp[0] = 1; for (int i=1; i<arr.length; i++) { int maxVal = 0; for (int j=0; j<i; j++) { if (arr[j] < arr[i] && dp[j] > maxVal) { maxVal = d [instruction] | Design a Java program to find the longest increasing sub-sequence of an array. [input] |
[output] | import math def magnitude(x, y, z): return math.sqrt(x * x + y * y + z * z) print(magnitude(1, 2, 3)) [instruction] | Write a Python program that prints out the magnitude of the three-dimensional vector with the following components: (x, y, z). [input] | (1, 2, 3)
[output] | squares = [x**2 for x in range(1, 11)] [instruction] | Create an array of elements that are the squares of the integers between 1 and 10 [input] |
[output] | def get_median(arr): sorted_arr = sorted(arr) length = len(sorted_arr) if length % 2 == 0: median1 = sorted_arr[int(length/2) - 1] median2 = sorted_arr[int(length/2)] median = (median1 + median2) / 2 else: median = sorted_arr[int((length-1)/2)] ret [instruction] | Write a function to calculate median of array elements [input] |
[output] | def items_and_prices(item1, item2, item3): switch = { 'item1': item1, 'item2': item2, 'item3': item3 } for key, value in switch.items(): print(key + ": " + str(value)) items_and_prices(25.00, 13.50, 3.99) [instruction] | Create a switch-case statement for a shopping cart to print out the items and their prices. [input] | Item1: $25.00 Item2: $13.50 Item3: $3.99
[output] | var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; [instruction] | Create an array that contains the numbers 1 through 10. [input] |
[output] | function degToRad(deg) { return deg * (Math.PI/180); } [instruction] | Create an angle converter function which converts degrees to radians. [input] |
[output] | UPDATE User SET name = 'Daniel' WHERE id = 1; [instruction] | Construct a necessary SQL query to update the name attribute in the User table. [input] | User table | id | name | |----|--------| | 1 | Johnny | Name to be updated: Daniel
[output] | div[text="Hello World"] { // CSS rules go here } [instruction] | Design a CSS selector for a div with a text of "Hello World". [input] |
[output] | <html> <head> </head> <body> <table> <thead> <tr> <th>Color</th> <th>Hexcode</th> </tr> </thead> <tbody> <tr> <td>Red</td> [instruction] | Produce an HTML webpage that shows a table of 10 colors and their corresponding hexcodes. [input] |