[output] | def count_words(text): return len(text.split()) [instruction] | Report the number of words in the following text. [input] | This is a sample text
[output] | def longest_common_subsequence(str1, str2): n = len(str1) m = len(str2) dp = [[0] * (m+1) for _ in range(n+1)] for i in range(1, n+1): for j in range(1, m+1): if str1[i-1] == str2[j-1]: dp[i][j] = 1 + dp[i-1][j-1] else: dp[i][j] = max(dp[i-1][j], dp[i][j-1 [instruction] | Find the length of the longest common subsequence in the following two strings: "ABCBDAB" and "BDCABA". [input] |
[output] | my_string = 'This is a sentence without any vowels' new_string = ''.join([i for i in my_string if i not in 'aeiouAEIOU']) print(new_string) [instruction] | Create a one line solution in Python to remove all vowels from a string. [input] |
[output] | RegExp("X", "i") [instruction] | Create a regular expression to check if a given string contains any the letter 'X'. [input] |
[output] | RegExp("[0-9]*[02468]") [instruction] | Write a regular expression that matches even numbers within a given string. [input] |
[output] | I was leaving for work. [instruction] | Edit the following sentence so that it becomes grammatically correct. [input] | Sentence: I was leaving to work.
[output] | SELECT e.name, COUNT(o.employee_id) as order_count FROM employees e INNER JOIN orders o ON e.id=o.employee_id GROUP BY e.name; [instruction] | Write an SQL query to produce an output which contains the name of the employee and the number of orders that employee has been responsible for. [input] |
[output] | <table> <tr> <th>Name</th> <th>Age</th> <th>Country</th> </tr> <tr> <td>John</td> <td>30</td> <td>USA</td> </tr> <tr> <td>Mary</td> <td>25</td> <td>Canada</td> </tr> <tr> <td>Jane</td> <td>40</td> <td>Australia</td> </tr> <table> [instruction] | Write HTML code to display the following table. [input] |
[output] | def merge_lists(lst1, lst2): sorted_list = [] i=j=0 while (i<len(lst1) and j<len(lst2)): if lst1[i] <= lst2[j]: sorted_list.append(lst1[i]) i+=1 else: sorted_list.append(lst2[j]) j+=1 sorted_list += lst1[i:] sorted_list += lst2[j:] return sorted_list [instruction] | Create an algorithm in Python to combine two sorted lists into a single sorted list. [input] | list1 = [3, 5, 7] list2 = [1, 2, 4]
[output] | import math def sin_deg(x): """ Returns the approximate value of the sine of x, given in degrees. """ return math.sin(math.radians(x)) [instruction] | Create a function in Python to return the approximate value of sin(x) using degrees [input] |
[output] | def sumThree(n1, n2, n3): """ This function returns the sum of three numbers If the values are equal, it will return triple their sum """ if n1 == n2 == n3: return 3 * (n1 + n2 + n3) else: return n1 + n2 + n3 [instruction] | Write a Python code to calculate the sum of three given numbers, if the values are equal, then return triple their sum [input] |
[output] | def is_prime(n): """ This function will check if a given number is prime or not. """ if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def generate_list_of_primes(n): """ This function will [instruction] | Generate a list of all the prime numbers in the range from 0 to the given number n. [input] |
[output] | def myFunc(): print(2) return print(1) [instruction] | Given the python code below, reverse the order of the lines to form a valid program. [input] | def myFunc(): print(1) return print(2)
[output] | The result of x = 2 and y = 3 in the function f(x,y) = x^3 + 2y^2 is 19. [instruction] | What is the result of x = 2 and y = 3 in this function, f(x,y) = x^3 + 2y^2? [input] |
[output] | def normalize_df(df): normalized_df=(df-df.min())/(df.max()-df.min()) return normalized_df norm_df = normalize_df(df) [instruction] | Create a function to normalize a given pandas dataframe. [input] |
[output] | def divide_list(numbers): even_list = [] odd_list = [] for num in numbers: if num % 2 == 0: even_list.append(num) else: odd_list.append(num) return even_list, odd_list # Driver Code numbers = [1, 2, 3, 4, 5, 6] even_list, odd_list = divide_lis [instruction] | Divide a list of numbers into two smaller lists, one with even numbers and one with odd numbers. [input] | [1, 2, 3, 4, 5, 6]
[output] | int a[5] = {2, 3, 4, 5, 1}; int maxNum = a[0]; for(int i = 1; i < 5; i++) { if(a[i] > maxNum) maxNum = a[i]; } // maximum number is: cout << maxNum << endl; [instruction] | Edit the given C++ code to find and print the maximum number in an array of integers. [input] | int a[5] = {2, 3, 4, 5, 1};
[output] | A memory leak in C++ occurs when a programmer allocates memory but fails to deallocate that memory when it is no longer needed. This results in memory being unnecessarily allocated and unavailable for other uses. This can lead to decreased performance as well as limit the amount of available memory, [instruction] | Explain the concept of memory leak in C++. [input] |
[output] | import random random_floats = [random.uniform(0, 1) for _ in range(15)] [instruction] | Create an array of 15 random floats in Python between 0 and 1. [input] |
[output] | SELECT name FROM customers WHERE customer_id = 100 [instruction] | Write a SQL query to find the name of a customer from a given customer id. [input] | customer_id: 100
[output] | function describe_variable_type($value) { if(is_int($value)) return 'integer'; elseif(is_float($value)) return 'float'; elseif(is_bool($value)) return 'boolean'; elseif(is_string($value)) return 'string'; else return 'unknown'; [instruction] | Write a PHP function to describe a variable type given the value. [input] | value: "Hello"
[output] | :nth-child(5n) [instruction] | Create a CSS selector to select every 5th element in a page. [input] |
[output] | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>My Webpage</title> </head> <body> <ol> <li>List Item 1</li> <li>List Item 2</li> <li>List Item 3</li> </ol> </body> </html> [instruction] | Edit the provided HTML structure to add an ordered list inside the body with 3 list items. [input] | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>My Webpage</title> </head> <body> </body> </html>
[output] | const Promise = (() => { let resolveCallbacks = []; let rejectCallbacks = []; const promise = (executor) => { executor((data) => { resolveCallbacks.forEach(callback => { callback(data); }); }, (error) => { rejectCallbacks.forEach(callback => { callback(error [instruction] | Implement a custom promise-based JavaScript library. [input] |
[output] | function sortByLength(arr) { return arr.sort((a, b) => a.length - b.length); } // Usage sortByLength(["a", "abc", "ab", "abcd", "abcde"]); // result: ["a", "ab", "abc", "abcd", "abcde"] [instruction] | Sort an array of strings based on their length. [input] | ["a", "abc", "ab", "abcd", "abcde"]
[output] | function generatePassword() { let characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; let password = ''; for (let i = 0; i < 8; i++) { let characterIndex = Math.floor(Math.random() * characters.length); let character = characters[characterIndex]; passwor [instruction] | Generate a random password with 8 characters long including lowercase letters, uppercase letters, and numbers. [input] |
[output] | function getLatestNews() { const url = 'http://newsapi.org/v2/top-headlines?country=world&apiKey=*****'; return fetch(url) .then(response => response.json()) .then(data => data.articles); } // Usage getLatestNews().then(headlines => console.log(headlines)); [instruction] | Make an API call to retrieve the latest news headlines for the world. [input] |
[output] | function stripHTMLTags(str) { return str.replace(/<[^>]*>/g, ""); } // Usage stripHTMLTags("<h1>Hello World</h1>"); // result: "Hello World" [instruction] | Remove all HTML tags from a string. [input] | "<h1>Hello World</h1>"
[output] | ip_address="176.4.3.39" netmask="255.255.255.0" default_gateway="176.4.3.253" # Configure network ifconfig eth0 ${ip_address} netmask ${netmask} route add default gw ${default_gateway} [instruction] | Configure the following network parameters [input] | ip_address = "176.4.3.39"; netmask = "255.255.255.0"; default_gateway = "176.4.3.253";
[output] | len(input) [instruction] | Read a line of input from the user and print the length of the line. [input] | Hello World.