[output] | In Java, you can count the number of elements in an array by using the length property of the array. For example, int[] arr = {1, 2, 3}; int len = arr.length; System.out.println("Length of the array: " + len); // Output: Length of the array: 3 [instruction] | How can you count the number of elements in an array in Java? [input] |
[output] | [6, 0, 9, 5] [instruction] | Generate a list of 4 random numbers between 0 and 10, without duplicates. [input] |
[output] | def top_three_words(string): words = string.split() word_dict = {} for word in words: if word in word_dict: word_dict[word] +=1 else: word_dict[word] = 1 sorted_dict = sorted(word_dict.items(), key = lambda x: x[1], reverse = True) top_thre [instruction] | Create a program to list the 3 most frequent words in a string. [input] | string = "I am learning Python programming language"
[output] | list_of_numbers = [30, 10, 20, 40, 50] list_of_numbers.sort() print(list_of_numbers) [instruction] | Edit the following code and make sure it prints out the sorted list instead of the unsorted list. [input] | list_of_numbers = [30, 10, 20, 40, 50]
[output] | The cat asked him to build the house. [instruction] | Output a random sentence based on the given grammar. [input] | <Noun> asked <Pronoun> to <Verb> the <Object>.
[output] | There are 3 "a"s in the sentence. [instruction] | Output the number of "a"s in the following sentence. [input] | The quick brown fox jumps over the lazy dog.
[output] | def closest_string_match(string, strings): min_distance = float("inf") min_string = "" for s in strings: distance = levenshtein_distance(string, s) if distance < min_distance: min_distance = distance min_string = s return min_string def leven [instruction] | Create a program to find the closest string to the given string from a list of strings. [input] | string = "text" strings = ["tens", "tent", "teach", "tewksbury"]
[output] | SELECT * FROM table_name WHERE Department = 'Sales'; [instruction] | Write an SQL query to select the rows which have "Sales" in the Department column. [input] |
[output] | #include <iostream> #include <string> using namespace std; //function to find common substring string longestCommonSubstring(string str1, string str2) { int m = str1.length(); int n = str2.length(); int table[m + 1][n + 1]; //fill the lookup table int res_len = 0; string [instruction] | Implement a function in C++ that takes two strings as parameters and returns the longest common substring between the two. [input] | str1 = "stackoverflow" str2 = "overburning"
[output] | // Linked List Structure struct Node { int data; struct Node* link; }; // Utility function to create a new node Node* newNode(int data) { Node* node = (Node*)malloc(sizeof(Node)); node->data = data; node->link = NULL; return node; } [instruction] | Implement a linked list using C language. [input] |
[output] | def isPalindrome(string): rev_string = string[::-1] if (string == rev_string): return True return False [instruction] | Create a function that checks if a given string is a palindrome (a string which reads the same forward and backward). [input] | string = "racecar"
[output] | SELECT * FROM table_name ORDER BY column_name DESC LIMIT 1; [instruction] | Write a SQL query to select the records with the highest values for a given column. [input] |
[output] | public static int[] removeDuplicates(int[] arr) { int n = arr.length; int[] temp = new int[n]; int j = 0; for (int i=0; i<n-1; i++){ if (arr[i] != arr[i+1]) temp[j++] = arr[i]; } temp[j++] = arr[n-1]; int[] res [instruction] | Write a Java method to remove repeated elements from an array. [input] |
[output] | import java.util.HashMap; HashMap<String, Integer> myMap = new HashMap<>(); // adding key-value pairs to the HashMap myMap.put("Key1", 5); myMap.put("Key2", 8); myMap.put("Key3", 10); // retrieving values by keys int val1 = myMap.get("Key1"); int val2 = myMap.get("Key2"); int val3 = myMap.get("Ke [instruction] | Using the Java collections API, create a data structure such as a HashMap to store key-value pairs. [input] |
[output] | total = 108 # Program list_of_numbers = [4, 8, 15, 16, 23, 42] total = sum(list_of_numbers) print(total) [instruction] | Create a program that takes a list of numbers and prints out the sum of those numbers. [input] | list_of_numbers = [4, 8, 15, 16, 23, 42]
[output] | Welcome, John Doe! We are so glad that you are here. [instruction] | Generate a customized welcome message that welcomes a given customer by name. [input] | customer_name = "John Doe"
[output] | def add_matrices(matrix1, matrix2): # assert that the matrices are of equal size assert len(matrix1) == len(matrix2), "Matrices should have the same size" assert len(matrix1[0]) == len(matrix2[0]), "Matrices should have the same size" # add the elements for i in range(len(matrix [instruction] | Write a code snippet that adds two matrices of equal sizes. [input] | matrix1 = [[1, 2], [3, 4]] matrix2 = [[5, 6], [7, 8]]
[output] | data = { "name": "John Doe", "age": 34, "hobbies": ["reading", "cycling", "movies"], "address": { "city": "London", "country": "United Kingdom" } } # Parse the json to a dictionary dictionary = json.loads(data) [instruction] | Create a dictionary and parse the following JSON object into it. [input] | { "name": "John Doe", "age": 34, "hobbies": ["reading", "cycling", "movies"], "address": { "city": "London", "country": "United Kingdom" } }
[output] | # Solve the equation def solve(x, y): return (20 - 5 * y) / 4 x = solve(4, 5) y = solve(5, 4) print(x, y) # Outputs: 3, 4 [instruction] | Create a code snippet that solves the following equation: 4x + 5y = 20 [input] |
[output] | x = 3 y = 3 # Print the value of x multiplied by y print(x * y) # Outputs: 9 [instruction] | Using the comment as a guide, implement the missing line of code necessary to print out the number 9. [input] | x = 3 y = 3 # Print the value of x multiplied by y
[output] | class Employee: def __init__(self, name, age, salary, role): self.name = name self.age = age self.salary = salary self.role = role # Create an employee employee = Employee("John Doe", 34, 10000, "Software Engineer") [instruction] | Use classes and objects to create an employee class with attributes such as name, age, salary, and role. [input] |
[output] | # Convert the list of dictionaries to pandas dataframe import pandas as pd df = pd.DataFrame(students) # Print the dataframe print(df) # Outputs: name age grade 0 John 18 85 1 James 16 82 2 Jill 17 89 [instruction] | Write a code snippet to convert the following list of dictionaries into a pandas dataframe. [input] | students = [{"name":"John", "age": 18, "grade": 85}, {"name":"James", "age": 16, "grade": 82}, {"name":"Jill", "age": 17, "grade": 89}]
[output] | import re def get_body_text(htmlString): matches = re.search(r'<body>(.*?)</body>', htmlString, re.MULTILINE | re.DOTALL) return matches.group(1) [instruction] | Generate a code to parse an HTML string and extract the body text only. [input] | <html> <body> test text <p> Some more text </p> </body> </html>
[output] | SELECT last_name FROM employees WHERE department = 'Tech' ORDER BY last_name DESC LIMIT 10; [instruction] | Write an SQL query to get the 10 last names of employees working in the “Tech” department. [input] |
[output] | import re def has_url(text): pattern = r"(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?" matches = re.findall(pattern, text) if matches: return True return False [instruction] | Write a Python script to detect if a given text contains any URL. [input] |
[output] | SELECT * FROM employees WHERE salary > 30000; [instruction] | Write an SQL query to find the employees that are making more than $30,000 in salary. [input] |
[output] | unsorted_list = [3, 5, 1, 0, 9] def sort_list(unsorted_list): sorted_list = sorted(unsorted_list) return sorted_list print(sort_list(unsorted_list)) [instruction] | Generate a program to sort the list. [input] | unsorted_list = [3, 5, 1, 0, 9]
[output] | from random import choice def flip_coin(): result = choice(['Heads', 'Tails']) print(result) if __name__ == "__main__": flip_coin() [instruction] | Generate a program to flip a coin. [input] |
[output] | list = ['apple', 'banana', 'cherry'] def transform_list(list): upper_list = [i.upper() for i in list] return upper_list print(transform_list(list)) [instruction] | Generate a code to transform the list of strings into the upper case. [input] | list = ['apple', 'banana', 'cherry']
[output] | def combine_lists(list_1, list_2): return list_1 + list_2 list_1 = [2, 4, 6] list_2 = [3, 5, 7] print(combine_lists(list_1, list_2)) [instruction] | Create a Python program that'll take two lists and return a combined list. [input] | list_1 = [2, 4, 6] list_2 = [3, 5, 7]