[output] | def is_anagram(string1, string2): # Create a dictionaries for strings string1_dict = {} string2_dict = {} # Add the chars from each string to the dictionaries for char in string1: if char not in string1_dict: string1_dict[char] = 1 else: [instruction] | Develop an algorithm in Python to determine whether two strings are anagrams. [input] |
[output] | """ Get the top 10 trending topics on Twitter with their volume using the Twitter API """ import tweepy #Authenticate to Twitter auth = tweepy.OAuthHandler("CONSUMER_KEY", "CONSUMER_SECRET") auth.set_access_token("ACCESS_KEY", "ACCESS_SECRET") #Create API Object api = tweepy.API(auth) #Get top 1 [instruction] | Write a code to get the top 10 trending topics on Twitter with their volume using the Twitter API. [input] |
[output] | <?php // Function to find the length of the longest common substring function lcsLength($str1, $str2) { // store the lengths of strings $len1 = strlen($str1); $len2 = strlen($str2); // Declare empty 2D array of size // (length of str1 x length of str2) [instruction] | Create a program using PHP to display the length of the longest common substring in two given strings. [input] |
[output] | def repeat_string(string, n): repeated = "" for letter in string: for _ in range(n): repeated += letter return repeated [instruction] | Print out the string formed by repeating each character in a given string n times. [input] | String: "abc", n: 3
[output] | def list_length(list): return len(list) [instruction] | Build a program that prints out the length of a given list. [input] |
[output] | def clamp_number(num, min_value, max_value): if num < min_value: return min_value elif num > max_value: return max_value else: return num [instruction] | Code a function to clamp a given number between a minimum value and maximum value. [input] | Number: 8, Minimum: 3, Maximum: 10
[output] | def expression_output(lst): s = 0 for i in lst: s += i**2 - 5*i + 6 return s [instruction] | Develop a program that prints out the output of the following expression. [input] | [2, 4, 6, 8]
[output] | netstat -an [instruction] | Construct a bash command to list all network connections in the system. [input] |
[output] | We can use the datetime.date class to store dates in ISO 8601 format. We just need to create an instance of datetime.date using the year, month and day. Then, we can convert it to the ISO 8601 format string using isoformat() method of datetime.date. For example: import datetime date = datetime.date( [instruction] | Suggest a solution to store years in ISO 8601 format in Python. [input] |
[output] | <div></div> [instruction] | Generate a short HTML div element. [input] |
[output] | def first_upper_char(input_string): if len(input_string) == 0: return '' else: return input_string[0].upper() [instruction] | Create a function in Python which takes a string as an argument and returns the first character of the string in upper case. [input] |
[output] | def average(a, b): return (a+b)/2 [instruction] | Write a script which receives two integers as parameters and returns their average as output. [input] |
[output] | import random def shuffle_list(my_list): random.shuffle(my_list) return my_list [instruction] | Write a script which takes a list as an argument and shuffles it. [input] | my_list = [1,2,3,4,5]
[output] | We can use a regular expression to validate a password. A regular expression to validate a password with at least 1 uppercase character, 1 lowercase character and 1 digit should be: ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$ If the password matches the regular expression, the password is valid. Otherwise, [instruction] | Suggest a solution for validating a password which should contain at least 1 uppercase character, 1 lowercase character and 1 digit. [input] |
[output] | def fibonacci(n): if n == 1: return 0 elif n == 2: return 1 else: return fibonacci(n-1) + fibonacci(n-2) [instruction] | Create a script in Python which takes a number as an argument and prints its corresponding nth Fibonacci number. [input] |
[output] | We can use the built-in sorted() function to sort the list of strings on the basis of their length in ascending order. The syntax for sorting is as follows: sorted(list_of_strings, key=len) where 'list_of_strings' is the list of strings we want to sort and 'len' is the length function for getting [instruction] | Suggest a method in Python for sorting a list of strings on the basis of their length in ascending order. [input] |
[output] | We can detect prime numbers in Python by using a for loop. The for loop will iterate over all numbers from 2 up to the given number. For each number we loop through, we check to see if the number is divisible by any other number greater than 1. If the number is divisible by any other number, then we [instruction] | Explain how to detect prime numbers in Python. [input] |
[output] | """ Train a machine learning model to classify cats and dogs """ import numpy as np import pandas as pd import matplotlib.pyplot as plt from keras.preprocessing.image import ImageDataGenerator from keras.models import Sequential from keras.layers import Conv2D, MaxPooling2D from keras.layers impor [instruction] | Train a machine learning model to classify cats and dogs. [input] |
[output] | import langdetect def detect_language(s): """ Detects the dominant language from a given string. Parameters ---------- s : str A string containing multiple languages Returns ------- str The dominant language found in the given string """ ret [instruction] | Write code to detect the dominant language in a string. [input] | This is a test string with multiple languages, including French, Spanish, and English.
[output] | class Division(): def __init__(self, x, y): self.x = x self.y = y def add(self): return self.x + self.y def subtract(self): return self.x - self.y def multiply(self): return self.x * self.y def divide(self): [instruction] | Write a class in Python to represent a division with two integers and the following operations: addition, subtraction, multiplication and division. [input] |
[output] | vector<int> v(10, 0); [instruction] | Introduce a vector of size 10 with all elements initialized to 0. [input] |
[output] | UPDATE TableB SET TableB.age = TableA.age FROM TableA WHERE TableB.name = TableA.name; [instruction] | Compare 2 databases and update non matching information from database A to database B using SQL. [input] | Table A: | name | age | |------|-----| | John | 20 | | Joe | 25 | Table B: | name | age | |------|-----| | John | 25 |
[output] | Head -> 2 -> 4 -> 5 -> 6 -> 7 -> None [instruction] | Create a linked list from the given array of numbers. [input] | [2, 4, 5, 6, 7]
[output] | def generate_fibonacci(n): a, b = 0, 1 fibonacci_series = [a] for i in range(n-1): a, b = b, a+b fibonacci_series.append(b) return fibonacci_series [instruction] | Implement a Fibonacci series generator using Python. [input] |
[output] | for i in range(500, 1000): flag = 1 for j in range(2, i): if i % j == 0: flag = 0 break if flag == 1: print(i) [instruction] | Construct a for loop that prints out all prime numbers between 500 and 1000 [input] |
[output] | if (day == "Sunday"){ console.log("Today is a holiday.") } else { console.log("Today is not a holiday.") } [instruction] | Construct an if-else statement that checks if the given day is a holiday [input] | day = "Sunday"
[output] | maxValue = 11 [instruction] | Compute the maximum value in a random array [input] | [4,6,9,2,11,7]
[output] | element = 15 [instruction] | Output the 7th element in the given array [input] | [5, 10, 20, 12, 15, 7]
[output] | sum = 3750 [instruction] | Create a program that finds the sum of all numbers divisible by 4 between 150 and 300 [input] |
[output] | print('Hello, World!') [instruction] | Write a Jupyter Notebook cell to print a greeting with the text "Hello, World!". [input] |