[output] | # Importing necessary libraries import pandas as pd import numpy as np from sklearn.feature_extraction.text import CountVectorizer from sklearn.naive_bayes import MultinomialNB # Loading the dataset df = pd.read_csv('emails.csv') # Feature engineering vectorizer = CountVectorizer() X = vectorizer. [instruction] | Write a code to classify emails as spam or not-spam using Naive Bayes algorithms. [input] |
[output] | def create_array(param1, param2): """A function that takes two parameters and returns an array with those two numbers in it.""" arr = [param1, param2] return arr # Let's test it arr = create_array(1, 5) print(arr) # Output: [1, 5] [instruction] | Create a function that takes two parameters and returns an array with those two numbers in it. [input] |
[output] | # Importing necessary libraries import bs4 import requests # Fetching the data url = "https://en.wikipedia.org/wiki/Main_Page" response = requests.get(url) soup = bs4.BeautifulSoup(response.text) # Extracting hyperlinks links = [] for link in soup.find_all('a'): links.append(link.get('href')) [instruction] | Write a code to extract all the hyperlinks from a Wikipedia page. [input] |
[output] | def is_valid_zip_code(zip_code): """ Function to check whether the given zip code is valid in the US """ valid_zip_code_pattern = re.compile(r"^[0-9]{5}(?:-[0-9]{4})?$") if valid_zip_code_pattern.match(zip_code): return True return False # Let's test it zip_code = "12345" pr [instruction] | Write a code to check for a valid zip code in US. [input] |
[output] | class StringPrinter extends React.Component{ render(){ console.log(this.props.string); return null; } } [instruction] | Create a React component that accepts a string as a parameter and prints it in the console. [input] |
[output] | public void swap(int[] arr, int i, int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } public void quickSort(int[] arr, int start, int end) { if (start < end) { int partitionIndex = partition(arr, start, end); quickSort(arr, start, partitionIndex-1); quickSort(arr [instruction] | Determine the most efficient way to sort a complex data structure using Java. [input] | [3, 4, 2, 7, 9, 1, 5]
[output] | // C++ Program to implement Search #include <bits/stdc++.h> using namespace std; // function to implement search int search(vector <int> list, int x) { // traversing the list for (int i = 0; i<list.size(); i++) if (list.at(i) == x) return i; return -1; [instruction] | Implement a search algorithm in C++ that takes in a list of integers and a target value and finds the index of the target if it exists in the list. [input] | List: [2, 4, 6, 8, 10], Target: 8
[output] | import xmltodict # open the XML document with open("document.xml") as f: xml_data = f.read() # convert to json json_data = xmltodict.parse(xml_data) # print the JSON object print(json.dumps(json_data, indent=2)) [instruction] | Transform a given XML document into a JSON object using Python. [input] |
[output] | #include<stdio.h> #include<string.h> int lcs( char *X, char *Y, int m, int n ) { int L[m + 1][n + 1]; int i, j; /* Following steps build L[m + 1][n + 1] in bottom up fashion. Note that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */ for [instruction] | Implement the longest common subsequence algorithm in C. [input] |
[output] | let string = "My telephone numbers are 123-456-7890 and 012-345-6789"; let regex = /\d{3}-\d{3}-\d{4}/g; let numbers = string.match(regex); console.log(numbers); [instruction] | Using regular expressions, extract all telephone numbers from a given string in JavaScript. [input] |
[output] | let list = document.getElementsByClassName("classname"); let elements = []; for (let i = 0; i < list.length; i++) { elements.push(list[i]); } console.log(elements); [instruction] | Parse a given HTML document and find all elements with the given class name using JavaScript. [input] |
[output] | def decimal_to_binary(num): result = "" while num > 0: remainder = num % 2 result = str(remainder) + result num = num // 2 return result [instruction] | Create a function to represent a decimal number in its binary form. [input] |
[output] | for item in data: if type(item) == int: print("Element is a number!") else: print("Element is not a number!") [instruction] | Write a code snippet to loop through an array and check if the element is a number or not. [input] | data = [1, 'a', 'b', 2]
[output] | <a href="https://www.example.com">Link</a> [instruction] | Suggest a completion to the following HTML code to add a link to a webpage. [input] | <a
[output] | Cross-site scripting (XSS) is a type of web application security vulnerability in which an attacker injects malicious code into webpages viewed by other users. The malicious code is typically a client-side script that is executed on the user's browser, such as JavaScript, HTML, and VBScript. This ty [instruction] | Explain what a cross-site scripting attack is. [input] |
[output] | function reverseString(str) { strArray = str.split(''); reversedStrArray = strArray.reverse(); return reversedStrArray.join(''); } [instruction] | Write a code snippet that reverses a string in JavaScript. [input] |
[output] | def print_even_numbers(n): for i in range(2, n*2, 2): print(i) [instruction] | Write a Python function that prints the first n even numbers. [input] |
[output] | function hasKey(obj, key) { if(obj.hasOwnProperty(key)) { return true; } return false; } [instruction] | Create a JavaScript code snippet to check if an object contains a specified key. [input] |
[output] | def join_sets(user_id1, firstname, user_id2, lastname): user_id = user_id1 + user_id2 names = firstname + lastname result = [] for id in user_id: firstname = [name for id, name in zip(user_id1, firstname) if id == id][0] lastname = [name for id, name in zip(user_id2, [instruction] | Given two data sets, one containing the user id (user_id) and first name (firstname) and another data set containing user_id and last name (lastname), write a Python function to join the two sets and create a new data set with firstname, lastname and user_id. [input] | user_id: [1,3,4,7] firstname: ["John", "Alice", "Madison", "Peter"] user_id: [1,2,3,6] lastname: ["Smith", "Jones", "Brown", "Miller"]
[output] | def count_capital_letters(string_list): count = 0 for string in string_list: for char in string: if char.isupper(): count += 1 return count [instruction] | Using the given list of strings, create a function to count and return the number of capital letters in the list. [input] |
[output] | def combine_lists(list1,list2): result = [] for i in list1: for j in list2: result.append([i,j]) return result [instruction] | Write a Python program to compute and return a list that contains every possible combination of two given lists. [input] | list1 = [1,2] list2 = [3,4]
[output] | def find_substring(main_string, substring): indices = [] position = -1 while True: position = main_string.find(substring, position + 1) if position == -1: break indices.append(position) return indices [instruction] | Create a function to return all the indices in a string where a given substring occurs. [input] |
[output] | if (number < 0): print('Error: Number cannot be negative.') [instruction] | Return an error message when a user inputs a negative number. [input] |
[output] | def is_even(number): if (number % 2 == 0): return True else: return False [instruction] | Create a function to detect even numbers. [input] |
[output] | import json data = json.loads(data) print('Name:', data['name']) print('Age:', data['age']) print('Street:', data['address']['street']) print('City:', data['address']['city']) print('Zip:', data['address']['zip']) [instruction] | Parse a JSON object and print out the elements. [input] | data = { 'name': 'John Doe', 'age': 32, 'address': { 'street': '123 Main St', 'city': 'New York', 'zip': 10010 } }
[output] | def compute_sum(numbers): total = 0 for num in numbers: total += num return total [instruction] | Generate a function that computes the sum of the numbers in a given list. [input] |
[output] | print('Name:', my_dict['name']) print('Age:', my_dict['age']) print('City:', my_dict['city']) [instruction] | Print out the values in the following dictionary. [input] | my_dict = { 'name': 'John Doe', 'age': 32, 'city': 'New York' }
[output] | class Student: def __init__(self,name,age,grade): self.name = name self.age = age self.grade = grade def get_name(self): return self.name def set_name(self,name): self.name = name def get_age(self): return self.age def set_age(self,age): self.age = age de [instruction] | Create a class to store student names, ages and grades. [input] |
[output] | def isArmstrong(num): s = 0 temp = num while temp > 0: digit = temp % 10 s += digit ** 3 temp //= 10 if num == s: return True else: return False for num in range(lower, upper + 1): if isArmstrong(num): print(num) [instruction] | Write a Python program to find all the Armstrong numbers between the given two numbers. An Armstrong number is a number such that the sum of its digits raised to the third power is equal to the number itself. [input] | lower = 100 upper = 2000
[output] | import nltk from nltk.sentiment.vader import SentimentIntensityAnalyzer def sentiment_analyzer(string): sid = SentimentIntensityAnalyzer() snt = sid.polarity_scores(string) return snt["compound"] sentiment_analyzer(string) [instruction] | Write a virtual assistant in Python to gauge the sentiment of a given string. [input] | string = "I had a terrible day"