[output] | sorted(set(lst)) # Output: [1, 2, 3, 4] [instruction] | Remove duplicates from the given list and sort it in ascending order [input] | lst = [1, 2, 3, 1, 4, 2]
[output] | def clean_string(string): output = "" for char in string: if char.isalpha(): output += char return output clean_string(string) # Output: Helloworld [instruction] | Create a function to remove all non alphabetical characters from thestring [input] | string = "Hello, world!"
[output] | even_lst = [] odd_lst = [] for num in lst: if num % 2 == 0: even_lst.append(num) else: odd_lst.append(num) [instruction] | Separate the given list into two lists for even and odd numbers [input] | lst = [1, 2, 3, 4, 5]
[output] | import itertools combinations = [''.join(i) for i in itertools.product(chars)] # Output: ["a", "b", "c", "ab", "ac", "ba", "bc", "ca", "cb", "abc", "acb", "bac", "bca", "cab", "cba"] [instruction] | Generate all possible combinations of strings that can be formed using the given characters [input] | chars = ["a", "b", "c"]
[output] | def replace_chars(string, char): output = "" for c in string: output += char return output replace_chars(string, char) # Output: xxxxx xxxxx [instruction] | Replace all characters in the given string with the given character [input] | string = "Hello World" char = "x"
[output] | def average(a, b, c): return (a + b + c) / 3 a = 2 b = 5 c = 7 average = average(a, b, c) print("Average of a, b and c is:", average) [instruction] | Modify the given program so that it can output the average of numbers a,b, and c. [input] | a = 2 b = 5 c = 7
[output] | def unique_chars(word): unique_characters = set() for char in word: if char not in unique_characters: unique_characters.add(char) return unique_characters word = "Hello World" unique_characters = unique_chars(word) print("Unique characters in ", word, "are:", unique_characters) [instruction] | Create an algorithm to print out the unique characters in a given string. [input] | word = "Hello World"
[output] | You will need to use an API like RSS API which can help you fetch the contents of the given URL. The API can be used for displaying the content of the RSS feed in a UI. Once you have setup the API, you will then need to create a UI which uses the API and display the RSS feed content on the iOS app. [instruction] | Create an ios app to display the content of a given RSS feed [input] | Url: https://www.nytimes.com/svc/collections/v1/publish/https://www.nytimes.com/section/world/rss.xml
[output] | UPDATE employee SET salary = 2000 WHERE employee_id = 1 [instruction] | Create a MySQL query to update the salary field of the employee [input] | Table - employee Field - salary
[output] | import React from 'react'; import {Pie} from 'react-chartjs-2'; const data = { labels: [ 'Red', 'Green', 'Yellow' ], datasets: [{ data: [300, 50, 100], backgroundColor: [ '#FF6384', '#36A2EB', '#FFCE56' ], hoverBackgroundColor: [ '#FF6384', '#36A2EB', '#FFCE56' ] }] [instruction] | Create a React component to render a pie chart [input] |
[output] | def find_duplicate(list): visited = set() for num in list: if num in visited: return num else: visited.add(num) return None list = [2,4,8,7,2,5] print(find_duplicate(list)) # Output: 2 [instruction] | Build a function to identify a duplicate element in a list [input] | list = [2,4,8,7,2,5]
[output] | first_name = 'John' last_name = 'Smith' full_name = first_name + ' ' + last_name [instruction] | Combine the two strings into one and save it as a variable called full_name. [input] | first_name = 'John' last_name = 'Smith'
[output] | The number of days from January 1, 2021 to June 30, 2021 is 152 days. [instruction] | Calculate the number of days from January 1, 2021 to June 30, 2021. [input] |
[output] | The output of the function will be 8. [instruction] | Given the function, predict the output. [input] | def foo(a, b): return a + b print(foo(3, 5))
[output] | for num in range(1, 6): print(num**2) [instruction] | Create a for loop that prints the square of each number from 1 to 5. [input] |
[output] | import re sentence = "I I am going to the the store" result = re.sub(r'\b(\w+)( \1\b)+', r'\1', sentence) print(result) # I am going to the store [instruction] | Using regular expressions, remove any duplicate words from the following sentence. [input] | sentence = "I I am going to the the store"
[output] | result = [x for x in range(101) if x % 8 == 0] print(result)# [0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 100] [instruction] | Output a list with all the numbers from 0 to 100 that are divisible by 8. [input] |
[output] | SELECT name FROM Employees WHERE departmentID = 7; [instruction] | Construct an SQL query to find the name of all employees in department ID 7. [input] |
[output] | public class Maximum { public static int getMax(int num1, int num2, int num3) { int max = num1; if (num2 > max) { max = num2; } if (num3 > max) { max = num3; } return max; } public static void main(String[] args) { int max = getMax(1,2,5); Syste [instruction] | Design a Java program to find the maximum of 3 numbers. [input] | 1, 2, 5
[output] | def count_match_chars(str1, str2) count = 0 str1.each_char.with_index do |char, index| count += 1 if char == str2[index] end count end puts count_match_chars('cook', 'book') #2 [instruction] | Develop a Ruby method to compare two strings and return the number of matching characters. [input] | "cook","book"
[output] | class TaskList { constructor() { this.tasks = [] } add_task(task) { this.tasks.push(task); } remove_task(task) { const i = this.tasks.indexOf(task); if (i !== -1) { this.tasks.splice(i, 1); } } count_tasks() { return this.tasks.length; } } [instruction] | Design a Data Structure in Javascript to store a list of tasks. [input] |
[output] | <?php $array_input = array('foo','bar','baz','foo','bar'); $result = array_count_values($array_input); foreach($result as $key=>$value){ echo "$key has $value occurrence(s).\n"; } // Output: foo has 2 occurrence(s). // bar has 2 occurrence(s). // baz has 1 occurrence(s). ?> [instruction] | Create a PHP program to print out the frequency of word occurrences in an array. [input] | ['foo', 'bar', 'baz', 'foo', 'bar']
[output] | #Function for finding common element between two lists common_element <- function(x, y){ intersect_list <- intersect(x, y) return(intersect_list) } x <- c(14,5,13) y <- c(5,11,9) #Calling the above function common_element(x, y) #5 [instruction] | Create an R program to find the intersecting element of two lists. [input] | x = c(14,5,13) y = c(5,11,9)
[output] | #import<Foundation/Foundation.h> @implementation CheckString -(BOOL)isStringPalindrome:(NSString*)inputString { BOOL isPalindrome = true; int lastIndex = [inputString length] - 1; for (int i = 0; i < [inputString length]/2; i++) { //compare character one by one if ( [instruction] | Generate an Objective-C code to check if a given string is palindrome or not. [input] | "racecar"
[output] | sumlist :: [Integer] -> Integer sumlist [] = 0 sumlist (x:xs) = x + sumlist xs -- Driver Code main = do print (sumlist [2,3,7,9]) -- Output: 21 [instruction] | Write a Haskell program to calculate the sum of list elements. [input] | [2,3,7,9]
[output] | #!/bin/bash echo -n "Enter a string: " read str rev_str="" len=${#str} # loop for (( i=$len-1; i>=0; i-- )) do rev_str=${rev_str}${str:$i:1} done # display echo "$rev_str" [instruction] | Write a shell script that takes input from the user, reverses the string, and prints it on the terminal. [input] |
[output] | function getMaxNum(arr){ return Math.max.apply(null, arr); } let maxNum = getMaxNum([3, 6, 8, 2, 9, 4, 10]); console.log(maxNum); // 10 [instruction] | Write a function in JavaScript that returns the maximum number from an array of numbers. [input] | [3, 6, 8, 2, 9, 4, 10]
[output] | class Triangle: def __init__(self, base, height): self.base = base self.height = height def calculate_area(self): area = (self.base * self.height) / 2 return area # Create triangle triangle = Triangle(10, 5) # Find the area area = triangle.calculate_area() [instruction] | Write an Object-Oriented Python program to find the area of a triangle given the base and the height. [input] |
[output] | for i in range(5): print("Welcome to Python Programming") [instruction] | Edit the code to print “Welcome to Python Programming” five times. [input] | print("Hello Python")
[output] | <form> <label>First Name:</label> <input type="text" name="firstname" /><br> <label>Last Name:</label> <input type="text" name="lastname" /><br> <label>Age:</label> <input type="text" name="age" /><br> <input type="submit" value="Submit" /> </form> [instruction] | Create a HTML form that takes 3 inputs: first name, last name, and age. [input] |