[output] | import pandas as pd df = pd.DataFrame({'Name': ['Alice', 'Bob', 'Carol'], 'Age': [26, 32, 12]}) df [instruction] | Construct an IPython code cell to display the content of a given pandas DataFrame. [input] | DataFrame: Name Age Alice 26 Bob 32 Carol 12
[output] | import React, {Component} from "react"; export default class App extends Component { render() { return ( <div> <h1>Hello React!</h1> <h2>Nice to meet you!</h2> </div> ) } } [instruction] | Modify the following react code to make it render an h2 tag. [input] | import React, {Component} from "react"; export default class App extends Component { render() { return ( <div> <h1>Hello React!</h1> </div> ) } }
[output] | $('ul li:first-of-type').hide(); [instruction] | Write a jQuery code to hide the first element of an HTML list. [input] | <ul> <li>Item One</li> <li>Item Two</li> <li>Item Three</li> </ul>
[output] | nums = [2, 3, 1, 4] nums.sort(reverse=True) print(nums) # Output: [4, 3, 2, 1] [instruction] | Fix the bug in the following code to sort a given list of numbers in descending order. [input] | nums = [2, 3, 1, 4]
[output] | string = 'hello world' print(string.upper()) # Output: 'HELLO WORLD' [instruction] | Take the string ‘hello world’ and convert it to uppercase. [input] |
[output] | import xml.etree.ElementTree as ET tree = ET.parse('test.xml') root = tree.getroot() first_attr = root[0].attrib['attr1'] print(first_attr) # Output: 'value1' [instruction] | Parse the given XML code and extract the value of the first attribute of the first element. [input] | <root> <item attr1="value1" attr2="value2"> <value>Logged</value> </item> </root>
[output] | import json json_data = "{\"name\": \"John Doe\", \"age\": 30}" array = json.loads(json_data) print(array) # Output: {'name': 'John Doe', 'age': 30} [instruction] | Create a script to convert JSON to an array. [input] | {"name": "John Doe", "age": 30}
[output] | console.log(3); [instruction] | Write a JavaScript code snippet to log the integer 3 to the web console. [input] |
[output] | import java.util.Scanner; public class StringLength { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String inputString = scanner.nextLine(); System.out.println("Length of the string is: "+ inputString.length()); } } [instruction] | Write a Java program to read in a string and print its length. [input] |
[output] | import java.util.Scanner; public class ArraySum { public static void main(String[] args) { int[] array = {2, 5, 9, 8, 6}; int sum = 0; for (int i = 0; i < array.length; i++) { sum = sum + array[i]; } System.out.println("The sum of the array is: "+sum); } } [instruction] | In Java, write a program to read in an array of 5 integers and output their sum. [input] | [2, 5, 9, 8, 6]
[output] | """ Create a function which converts a string representation of number in English to a numerical value. """ def convert_english_number(number_string): word_values = {"one":1,"two":2,"three":3,"four":4,"five":5,"six":6,"seven":7,"eight":8,"nine":9,"ten":10,"eleven":11,"twelve":12,"thirteen":13," [instruction] | Create a function which converts a string representation of number in English to a numerical value. [input] | "one thousand two hundred and thirty four"
[output] | """ Create an algorithm to find the optimal sum from a set of given numbers such that the sum is equal to a given target. """ def optimal_sum(target, numbers): if (target == 0): return True n = len(numbers) subset = [True] + [False]*target for i in range(n): [instruction] | Create an algorithm to find the optimal sum from a set of given numbers such that the sum is equal to a given target. [input] | Target: 10 Numbers: [1,4,5,3,6]
[output] | """ Generate a loop to read each word from a given sentence and display them as a list. """ sentence = "Python is a great programming language" words = sentence.split() word_list= [] for word in words: word_list.append(word) print(word_list) [instruction] | Generate a loop to read each word from a given sentence and display them as a list. [input] | Sentence: "Python is a great programming language"
[output] | """ Create a function which receives two strings and checks if the characters in the first string appear in the same order as in the second string. """ def check_order(str1,str2): stack=[] j=0 for i in range(len(str2)): if str2[i]==str1[j]: stack.append(str2[i]) [instruction] | Create a function which receives two strings and checks if the characters in the first string appear in the same order as in the second string. [input] | String 1: "Hello World" String 2: "World Hello"
[output] | """ Use features of the Python language to implement 3-way partitioning of a given array. """ def threeWayPartition(array, pivot): less = [] equal = [] greater = [] for i in array: if i < pivot: less.append(i) elif i == pivot: equal.app [instruction] | Use features of the Python language to implement 3-way partitioning of a given array. [input] | Array: [9,6,7,4,1,6,3]
[output] | """ Create a data structure to store all of the prime numbers up to 1 million. """ import math def sieveOfEratosthenes(n): prime_numbers = [True]*(n+1) prime_numbers[0] = False prime_numbers[1] = False for i in range(2, int(math.sqrt(n)+1)): if (prime_numbers[i]): [instruction] | Create a data structure to store all of the prime numbers up to 1 million. [input] |
[output] | """ Create a function to edit a given string, replacing all the vowels with a given character. """ def replace_vowels(string, replacement_character): vowels = ['a', 'e', 'i', 'o', 'u'] new_str = "" for char in string: if char in vowels: new_str += replacement_characte [instruction] | Create a function to edit a given string, replacing all the vowels with a given character. [input] | String: "Hello world" Character: 'x'
[output] | """ Generate a loop to find the largest sub-array in a given array with contiguous elements and its sum. """ def largest_subarray_sum(array): best_sum = 0 current_sum = 0 current_start_index = 0 best_start_index = -1 best_end_index = -1 for i in range(len(array)): cu [instruction] | Generate a loop to find the largest sub-array in a given array with contiguous elements and its sum. [input] | Array: [-2, 6, -3, 5, -2, 3, 4, -2]
[output] | function myFunc(a, b) { return a + b; } //Compiled Version const myFunc = (a, b) => a + b; [instruction] | Compile the following code to JavaScript and return the compiled code. [input] | function myFunc(a, b) { return a + b; }
[output] | 0, 1, 1, 2, 3 [instruction] | Print the Fibonacci sequence up to the 5th element. [input] |
[output] | git clone https://github.com/shreya23/Coding-Challenges.git [instruction] | Clone the content of the following Github repository: https://github.com/shreya23/Coding-Challenges [input] |
[output] | def has_special_characters(s): return not all(char.isalnum() for char in s) [instruction] | Create a function that takes a string and checks if the string contains any special characters. [input] | Hello World
[output] | def two_sum(nums, target): for i in range(len(nums) - 1): for j in range(i+1, len(nums)): if nums[i] + nums[j] == target: return (i, j) return -1 [instruction] | We have a list of numbers and a given sum. Write a program to determine if any two numbers from the list sum up to the given sum. [input] | [1,2,3,4], 6
[output] | def get_long_words(s): words = s.split(" ") result = [] for word in words: if len(word) > 5: result.append(word) return result [instruction] | Create a function that takes in a string and returns an array of the words which are longer than 5 characters. [input] | "Welcome to the world of programming"
[output] | 1. Bubble Sort. 2. Selection Sort. 3. Insertion Sort. [instruction] | Name at least three sorting algorithms that can be implemented in PHP. [input] |
[output] | 1. The simplest way is to use the Square Bracket ([]) Notation. For example, hashmap[key] = value allows you to insert key-value pair into a hashmap. 2. The other way to insert elements into a hashmap is by using the update() method. This method takes in a dictionary object as an argument and updat [instruction] | Describe two ways to insert elements into a hashmap in Python. [input] |
[output] | DELETE FROM table_name WHERE id = <value>; [instruction] | How would you use PostgreSQL to delete a row with a given ID from a table? [input] |
[output] | K Nearest Neighbors (KNN) classification is a supervised machine learning algorithm used for solving classification problems. The main feature of the KNN algorithm is that it defines the class of a data sample based on the classes of its closest K neighbors, determined using a distance measure. It i [instruction] | Describe the features of the K Nearest Neighbors (KNN) classification algorithm. [input] |
[output] | int x = 5; if (x > 0) { std::cout << "x is positive"; } else { std::cout << "x is negative or zero"; } [instruction] | Provide an example of an if-else statement in C++. [input] |
[output] | One way to use Machine learning to classify the sentiment of a given text is to use a supervised Machine learning algorithm such as Support Vector Machines to build a classifier. The classifier can be trained on a labeled dataset which contains texts with corresponding labels like 'positive' or 'neg [instruction] | How could you use Machine learning to classify the sentiment of a given text? [input] |