[output] | def find_max_three(nums): max1 = - float('inf') max2 = - float('inf') max3 = - float('inf') for num in nums: if num > max1: max3 = max2 max2 = max1 max1 = num elif num > max2: max3 = max2 max2 = num [instruction] | How would you find the maximum 3 elements from a list of numbers? [input] | [20, -50, 15, 55, 0 , 40]
[output] | import json def json_to_dict(json_str): return json.loads(json_str) if __name__ == "__main__": json_str = """ { "name": "John Doe", "age": 25, "address": { "street": "123 Main Street", "city": "Los Angeles", "state": "CA", [instruction] | Transform the following JSON object into a Python dictionary. [input] | { "name": "John Doe", "age": 25, "address": { "street": "123 Main Street", "city": "Los Angeles", "state": "CA", "zip": 90001}}
[output] | A set is an unordered collection of items while a list is an ordered collection of items. Sets have no duplicate elements so all the elements in a set must be unique. The elements inside a list may or may not be unique. Sets are faster when compared to lists for retrieving elements since lookups of [instruction] | Compare and contrast the differences between sets and lists in Python. [input] |
[output] | Neural networks are inspired by the structure and function of biological neural networks. They are composed of layers of interconnected ‘neurons’, which contain adjustable weights that represent the strength of the connection between each neuron. The neurons receive an input from a source, process t [instruction] | Explain how a neural network works. [input] |
[output] | Python and Java are two of the most popular programming languages in the world. Python is a high-level, interpreted, general-purpose programming language while Java is a statically-typed, object-oriented language. Python is primarily used for web development, scripting and data science while Java is [instruction] | Summarize the features and differences between Python and Java. [input] |
[output] | public boolean isLeapYear(int year) { if(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) return true; else return false; } [instruction] | Create a boolean function in Java to check if a year is a leap year. [input] |
[output] | def unique_strings(string_list): return list(set(string_list)) [instruction] | Given a list of strings, create a function that returns a list of only the unique strings. [input] | ["this", "is", "a", "list", "of", "strings", "this", "list", "has", "some", "duplicates"]
[output] | def count_words(s): words = s.split() returnCounter = dict.fromkeys(words, 0) for word in words: returnCounter[word] += 1 return returnCounter [instruction] | Return a dictionary containing the number of occurrences of each word in the string. [input] | s = "this string should contain 4 occurrences of the word should"
[output] | def print_grid(n): for r in range(n): print("* "*n) [instruction] | Write a function that takes an integer n and prints the n x n grid with stars. [input] | 3
[output] | def parse_ingredients(html): soup = BeautifulSoup(html, 'html.parser') ingredients = [li.text for li in soup.find_all('li')] return ingredients [instruction] | Parse the following HTML string and find the ingredients for the recipe. [input] | <div> <h1>Chocolate Brownie Recipe</h1> <ul> <li>1/2 cup All-Purpose Flour</li> <li>1/3 cup Unsalted Butter</li> <li>1 cup Sugar</li> <li>2 Eggs</li> <li>3/4 cup Cocoa Powder</li> </ul> </div>
[output] | def same_length(string1, string2): return len(string1) == len(string2) [instruction] | Create a function that takes two strings and returns true if both strings have the same length and false otherwise. [input] | string1 = "hello" string2 = "world"
[output] | def print_divisible_by_5(input_list): for num in input_list: if num % 5 == 0: print(num) [instruction] | Given a list of numbers, create a function that prints the elements of the list that are divisible by 5. [input] | [1, 20, 30, 15, 60]
[output] | def sum_is_even(input_list): return sum(input_list) % 2 == 0 [instruction] | Create a function that takes a list of numbers and returns True if the sum of the numbers is even and False otherwise. [input] | [2, 4, 6, 8]
[output] | The easiest way to install the Pillow package is through pip, the official package manager for Python. To install Pillow using pip, open the command line interface and type "pip install Pillow". [instruction] | How to install the Python package called Pillow? [input] |
[output] | abstract class AbstractClass { abstract void funOne(); abstract void funTwo(); public static void main(String[] args) { // Code goes here } } [instruction] | Implement a main method for the following abstract class. [input] | abstract class AbstractClass { abstract void funOne(); abstract void funTwo(); }
[output] | x = -3 [instruction] | What is the result of the following operation in Python? [input] | x = 1 y = 3 z = 4 x = y - z
[output] | The algorithm would first compare the two arrays and select the lower value for the first element of the median. Then it would proceed to select the higher value for the second element of the median, and then average the two elements to obtain the median of the two sorted arrays. [instruction] | Design an algorithm to find the median of two sorted arrays. [input] |
[output] | The simplest way to create a dictionary of length four in Python is by using the built-in dict() function. For example: myDict = dict(key1 = "value1", key2 = "value2", key3 = "value3", key4 = "value4") [instruction] | How to create a dictionary of length four in Python? [input] |
[output] | The algorithm must traverse the list and keep track of the nodes as it moves through it. The algorithm should create a new linked list with the elements in reverse order. To do this, the algorithm should traverse the original linked list and push every element onto a stack. Then, the algorithm shoul [instruction] | Given a linked list, design an algorithm to reverse it. [input] |
[output] | def isPalindrome(string): '''This function will return whether or not a string is a palindrome.''' stack = [] for letter in string: stack.append(letter) reverse = '' while stack: reverse += stack.pop() if reverse == string: return True return Fa [instruction] | Implement the following function using a stack. [input] | def isPalindrome(string): '''This function will return whether or not a string is a palindrome.'''
[output] | func addTwoIntegers(a: Int, b: Int) -> Int { return a + b } [instruction] | Change the following Java code to Swift. [input] | public static int addTwoIntegers(int a, int b) { return a+b; }
[output] | int [] numArray = new int[5]; [instruction] | Create an array in Java to store 5 integer values. [input] |
[output] | for element in myArray: print(element) [instruction] | Create a for loop in Python to print all elements in a given numpy array. [input] | import numpy as np myArray = np.array([1, 2, 3, 4])
[output] | class MyClass { public: int publicMember; private: int privateMember; }; [instruction] | Create a class in C++ with one public member and one private member. [input] |
[output] | for (auto& item : myList) { cout << item << endl; } [instruction] | Create a for loop in C++ to traverse a list of strings. [input] | myList = ['Hello', 'World', '!']
[output] | switch (characterType) { case ‘A’ : // do something break; case ‘B’ : // do something break; case ‘C’ : // do something break; } [instruction] | Create a switch statement in Java to determine a given character type. [input] |
[output] | echo date('F j, Y'); [instruction] | Write a PHP code snippet to display the current date in the format "Month day, Year". [input] |
[output] | for (var i=1; i <= 10; i++) { console.log('Counting: ' + i); } [instruction] | Create a loop in JavaScript to count from 1 to 10. [input] |
[output] | The sentence "Jack and Jill went up the hill" can be tokenized into the following four tokens: ["Jack", "and", "Jill", "went", "up", "the", "hill"]. [instruction] | How could you tokenize a sentence "Jack and Jill went up the hill." [input] |
[output] | int[] arr = {4, 9, 3, 6, 2, 1}; Arrays.sort(arr); System.out.println(Arrays.toString(arr)); // Output: [1, 2, 3, 4, 6, 9] [instruction] | Sort the given array in Java [4, 9, 3, 6, 2, 1]. [input] |