messages listlengths 2 2 | conversation_id int64 0 20k |
|---|---|
[
{
"content": "Write an API to return the average transaction amount of a customer.",
"role": "user"
},
{
"content": "@app.route('/get_average_transaction_amount', methods=['GET'])\ndef get_average_transaction_amount():\n customer_id = request.args.get('customer_id')\n query = \"SELECT AVG(tran... | 600 |
[
{
"content": "Edit a python function to generate the fibonacci sequence.\ndef fibonacci(n):\n a = 1\n b = 0\n for i in range(n):\n print(a)\n a, b = b, a+b",
"role": "user"
},
{
"content": "def fibonacci(n):\n a = 0\n b = 1\n for i in range(n):\n print(a)\n ... | 601 |
[
{
"content": "Use the Gaussian algorithm to learn the optimal parameters of a 2D linear regression model.\nTraining dataset: {(x1,y1), (x2,y2), (x3,y3)}",
"role": "user"
},
{
"content": "def gaussian(x, y):\n n = len(x)\n l = np.linalg.inv(np.dot(x.T, x))\n k = np.dot(x.T, y)\n return np... | 602 |
[
{
"content": "Create an HTML page to display a table of students\nData of students: First name, LastName and Age",
"role": "user"
},
{
"content": "<html>\n <head> <title>My Student Table </title> </head>\n <body>\n <table>\n <thead>\n <tr>\n <th>First Name</th>\n <... | 603 |
[
{
"content": "Add the code for a sleep() function to the following script.\n#This script will be used to write a status update in Slack.\nimport os\n\ndef update_status(message):\n os.system('curl -X POST --data '{ \"text\": \"' + message + '\"}'' .....)",
"role": "user"
},
{
"content": "#This sc... | 604 |
[
{
"content": "Write a JavaScript function to check whether a given number is odd or even.\nnum = 21",
"role": "user"
},
{
"content": "function isEvenNumber(num) {\n return num % 2 === 0;\n}\n\nlet result = isEvenNumber(21);\nconsole.log(result); //false",
"role": "assistant"
}
] | 605 |
[
{
"content": "Explain what a for loop does in Python.",
"role": "user"
},
{
"content": "A for loop in Python is used to iterate over a sequence (list, tuple, string) or other iterable objects. It executes a set of statements specified in the for loop for each item of the sequence. It makes it easier... | 606 |
[
{
"content": "Create an HTML table with 3 columns containing the given data.\nData:\nName | Age | Hobby\nAlice | 20 | Reading\nBob | 25 | Outdoor activities",
"role": "user"
},
{
"content": "<table>\n <tr>\n <th>Name</th>\n <th>Age</th>\n <th>Hobby</th>\n </tr>\n <tr>\n <td>Alice</td>... | 607 |
[
{
"content": "Write a Java program to print the sum of all integers from 1 to given integer.\ninteger = 5",
"role": "user"
},
{
"content": "public class SumIntegers {\n \n public static void main(String[] args) {\n int n = 5;\n int sum = 0;\n for (int i = 1; i <= n; i++) {\n ... | 608 |
[
{
"content": "Suggest a better algorithm to find the minimum element in a given array.",
"role": "user"
},
{
"content": "The better algorithm would be to use a divide and conquer approach. This approach involves splitting the array into two halves, finding the minimum element in each half and then c... | 609 |
[
{
"content": "Explain what API stands for and what it does.",
"role": "user"
},
{
"content": "API stands for Application Programming Interface, which is a set of routines, protocols, and tools used to build software applications. It defines how two applications can interact with each other and allow... | 610 |
[
{
"content": "Complete the following code to shuffle an array of elements.\n#Declaring an array\narr = [1, 2, 3, 4, 5]\n\n# Your code\ndef shuffle(arr):",
"role": "user"
},
{
"content": "#Declaring an array\narr = [1, 2, 3, 4, 5]\n\n# Your code\ndef shuffle(arr): \n for i in range(len(arr)-1, 0,... | 611 |
[
{
"content": "Suggest an efficient data structure to store a list of words.",
"role": "user"
},
{
"content": "A Trie (Prefix Tree) data structure is an efficient data structure for storing a list of words. It allows efficient insertion, deletion and search operations. It stores the words in a hierar... | 612 |
[
{
"content": "Write a Python program to print out the list of even numbers from 0 to given limit.\nlimit = 10",
"role": "user"
},
{
"content": "# declare list of numbers\nnumbers = [x for x in range(0, limit+1)]\n\n# declare empty list of even numbers\neven_numbers = []\n\n# loop through list of num... | 613 |
[
{
"content": "Write a PHP program to find the largest number from an array.\narray = [10, 25, 2, 39]",
"role": "user"
},
{
"content": "<?php\n$arr = array(10, 25, 2, 39);\n$max = $arr[0];\n \nforeach ($arr as $value) {\n if ($value > $max) {\n $max = $value;\n }\n}\n \necho $max; // Output:... | 614 |
[
{
"content": "Write a for-loop to print out the values from a list named 'mylist'\nmylist = [1,2,3,4,5,6,7]",
"role": "user"
},
{
"content": "for i in mylist:\nprint(i)",
"role": "assistant"
}
] | 615 |
[
{
"content": "Create a class in Python called 'Car' and add instance variables for the car's make, model and year.",
"role": "user"
},
{
"content": "class Car:\n \n def __init__(self, make, model, year):\n self.make = make\n self.model = model\n self.year = year",
"rol... | 616 |
[
{
"content": "Use the 'requests' library to retrieve the HTML content of a website.\nurl = \"https://www.example.com\"",
"role": "user"
},
{
"content": "import requests\n\nhtml = requests.get(url).text",
"role": "assistant"
}
] | 617 |
[
{
"content": "Write a regular expression to extract all email addresses from a string.\nstring = \"My email address is john@doe.com and your email address is jane@doe.com\"",
"role": "user"
},
{
"content": "import re\n\nemails = re.findall(r\"[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+\", string... | 618 |
[
{
"content": "Initialize an empty list in Python and then add three items to it.",
"role": "user"
},
{
"content": "my_list = []\nmy_list.append(\"item1\")\nmy_list.append(\"item2\")\nmy_list.append(\"item3\")",
"role": "assistant"
}
] | 619 |
[
{
"content": "Calculate the sum of all the numbers in a list named 'mylist'.\nmylist = [1,2,3,4,5]",
"role": "user"
},
{
"content": "total_sum = 0\nfor num in mylist:\n total_sum += num\nprint(total_sum)",
"role": "assistant"
}
] | 620 |
[
{
"content": "Convert a string to all lowercase using the built-in string method.\nstring = \"This Is A String\"",
"role": "user"
},
{
"content": "lowercase_string = string.lower()\nprint(lowercase_string)",
"role": "assistant"
}
] | 621 |
[
{
"content": "Group a list of dictionaries by a shared key.\nmylist = [{'name': 'john', 'age': 20}, {'name': 'jane', 'age': 19}, {'name': 'bob', 'age': 22}]",
"role": "user"
},
{
"content": "from collections import defaultdict\n\ngrouped_dicts = defaultdict(list)\n\nfor x in mylist:\n grouped_dicts[... | 622 |
[
{
"content": "Create a dictionary from two lists with the same length.\nmylist1 = [\"a\", \"b\", \"c\", \"d\"]\nmylist2 = [\"1\", \"2\", \"3\", \"4\"]",
"role": "user"
},
{
"content": "mydict = dict(zip(mylist1, mylist2))\nprint(mydict)",
"role": "assistant"
}
] | 623 |
[
{
"content": "Perform a linear search in a list named 'mylist' and return the index of the first occurrence of a target value.\nmylist = [1, 2, 3, 4, 5, 6, 7]\ntarget = 4",
"role": "user"
},
{
"content": "def linear_search(mylist, target):\n for i in range(len(mylist)):\n if mylist[i] == target:\n r... | 624 |
[
{
"content": "Generate a random number between 1 and 10, inclusive.",
"role": "user"
},
{
"content": "import random\n\nrandom_num = random.randint(1, 10)\nprint(random_num)",
"role": "assistant"
}
] | 625 |
[
{
"content": "Use the built-in sort method to sort a list of strings by their length.\nmylist = ['this', 'is', 'a', 'long', 'list', 'of', 'strings']",
"role": "user"
},
{
"content": "mylist.sort(key=len)\nprint(mylist)",
"role": "assistant"
}
] | 626 |
[
{
"content": "Use the 'subprocess' library to execute a shell command and store its output.\ncommand = \"echo hello world\"",
"role": "user"
},
{
"content": "import subprocess\n\nresult = subprocess.run(command, shell=True, capture_output=True)\nprint(result.stdout.decode('utf-8'))",
"role": "as... | 627 |
[
{
"content": "Create a method to print all the prime numbers up to n.",
"role": "user"
},
{
"content": "def print_prime_numbers(n):\n primes = [] \n for num in range(2, n + 1): \n is_prime = True\n for i in range(2, num): \n if (num % i == 0): \n is_prim... | 628 |
[
{
"content": "Implement a reverse method to reverse the content of an array.\n[1, 2, 3, 4, 5]",
"role": "user"
},
{
"content": "def reverse(arr): \n n =len(arr) \n for i in range(n // 2): \n temp = arr[i] \n arr[i] = arr[n - i - 1] \n arr[n - i - 1] = temp\n \n return ... | 629 |
[
{
"content": "Retrieve the number of letters in the following phrase .\n\"May the force be with you!\"",
"role": "user"
},
{
"content": "22",
"role": "assistant"
}
] | 630 |
[
{
"content": "Create a method to checkout the content of dictionary.",
"role": "user"
},
{
"content": "def check_dict(dictionary):\n for key in dictionary:\n print(key + \": \" + str(dictionary[key]))",
"role": "assistant"
}
] | 631 |
[
{
"content": "You need to read a list of strings, split each into 2 substrings, and output the 2 substrings as a tuple.\n['international', 'imagination', 'skyscraper']",
"role": "user"
},
{
"content": "def split_words(string_list):\n new_list = []\n for string in string_list:\n mid = in... | 632 |
[
{
"content": "Create a program to find the sum of all the even numbers from 1 to n.",
"role": "user"
},
{
"content": "def find_sum(n): \n sum = 0\n for i in range (1, n): \n if (i % 2 == 0): \n sum = sum + i \n return sum",
"role": "assistant"
}
] | 633 |
[
{
"content": "Create a function to find if a given input is a prime number or not.",
"role": "user"
},
{
"content": "def is_prime(n):\n if n < 2:\n return False\n for i in range(2, int(n ** 0.5) + 1):\n if n % i == 0:\n return False \n return True",
"role... | 634 |
[
{
"content": "Calculate the result of raising 2 to the power of 6.",
"role": "user"
},
{
"content": "64",
"role": "assistant"
}
] | 635 |
[
{
"content": "Create a method to reverse a linked list.",
"role": "user"
},
{
"content": "def reverse_list(head): \n \n prev = None\n current = head \n while(current is not None): \n next = current.next\n current.next = prev \n prev = current \n current = next\n... | 636 |
[
{
"content": "Print out the content of a two-dimensional array.\n[[1, 2, 3], [4, 5, 6], [7, 8, 9]]",
"role": "user"
},
{
"content": "def print_2d_array(arr):\n for row in arr:\n for el in row:\n print(el, end=' ')\n print(\"\")",
"role": "assistant"
}
] | 637 |
[
{
"content": "Create a JavaScript function that prints out the numbers from 1 to n.",
"role": "user"
},
{
"content": "function printNumbers(n) {\n for (let i = 1; i <= n; i++) {\n console.log(i);\n }\n}",
"role": "assistant"
}
] | 638 |
[
{
"content": "Create a Swift function to find the sum of elements in an array of integers.\nlet arr = [1,2,3,4,5]",
"role": "user"
},
{
"content": "func sumOfElements(arr: [Int]) -> Int {\n let sum = arr.reduce(0, +)\n return sum\n}",
"role": "assistant"
}
] | 639 |
[
{
"content": "Create a JavaScript class that returns the area and circumference of a circle when given the radius.",
"role": "user"
},
{
"content": "class Circle {\n constructor(radius) {\n this._radius = radius;\n }\n \n get area() {\n return Math.PI * this._radius * this._radius;\n }\n \... | 640 |
[
{
"content": "Write SQL code to find the product details of the item with ID 1234.",
"role": "user"
},
{
"content": "SELECT * FROM products WHERE id = 1234;",
"role": "assistant"
}
] | 641 |
[
{
"content": "Write a C# program to create the list of prime numbers in a given range.",
"role": "user"
},
{
"content": "public class PrimeNumber\n{\n static void Main()\n {\n int n1 = 2;\n int n2 = 10;\n while (n1 < n2)\n {\n bool isPrime = true;\n for (int i = 2; i <= n1 / 2; i++)\n {\n if (n1 % i... | 642 |
[
{
"content": "Build a deep learning model in Python to predict the stock price of a given company.",
"role": "user"
},
{
"content": "# import libraries\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n# import data\ndata = pd.read_csv('stock_data.cs... | 643 |
[
{
"content": "Write an R script to find the correlation between two variables.",
"role": "user"
},
{
"content": "# read the data\ndat <- read.csv(\"data.csv\")\n\n# calculate the correlation\ncor(dat$var1, dat$var2)",
"role": "assistant"
}
] | 644 |
[
{
"content": "Write a JavaScript function to sort an array of integers.",
"role": "user"
},
{
"content": "function sortArray(arr) {\n return arr.sort(function(a, b) {\n return a - b;\n });\n}",
"role": "assistant"
}
] | 645 |
[
{
"content": "Write a SQL query to find the most expensive item in the table.",
"role": "user"
},
{
"content": "SELECT * FROM items ORDER BY price DESC LIMIT 1;",
"role": "assistant"
}
] | 646 |
[
{
"content": "Write a Java program to find the sum of elements in a 3x3 matrix.",
"role": "user"
},
{
"content": "// Java program to find sum of elements in a matrix \npublic class Matrix \n{ \n\tpublic static void main(String[] args) \n\t{ \n\t\t// Initialize matrix \n\t\tint[][] matrix = {{1, 2, 3... | 647 |
[
{
"content": "Describe in one sentence what is wrong with the following Java code.\npublic class Main {\n public static void main(String[] args) {\n int y;\n y = 10 + 5;\n y -= 30;\n }\n}",
"role": "user"
},
{
"content": "The code does not do anything with the value of y, ... | 648 |
[
{
"content": "To what type of data can the following MySQL query return?\nSELECT *\nFROM table1 t1\nINNER JOIN table2 t2\nON t1.id = t2.id",
"role": "user"
},
{
"content": "The query can return results of any combination of columns from the two tables. It will return a set of records with the matchi... | 649 |
[
{
"content": "Write a function in Python that takes a list of numbers and returns the greatest difference between any two numbers in the list.\ntest_list = [4, 6, 8, 10, 3, 1, 9]",
"role": "user"
},
{
"content": "def greatest_difference(numbers_list):\n max_difference = 0\n for num1 in numbers... | 650 |
[
{
"content": "Construct an XML element with tag 'hello' and the text 'Welcome to my website'.",
"role": "user"
},
{
"content": "<hello>Welcome to my website</hello>",
"role": "assistant"
}
] | 651 |
[
{
"content": "What will be the result of the following Ruby code?\na = 11\nb = 3\nc = a % b",
"role": "user"
},
{
"content": "The result of the code will be 2.",
"role": "assistant"
}
] | 652 |
[
{
"content": "Explain what is wrong with the following SQL statement.\nSELECT column1, column2 FROM myTable;",
"role": "user"
},
{
"content": "The statement does not specify which records in MyTable it is attempting to retrieve, so it will return all columns of all records in the table.",
"role"... | 653 |
[
{
"content": "Construct a SQL query to get all CustomerIDs from the Orders table if their OrderTotal is greater than 500.",
"role": "user"
},
{
"content": "SELECT CustomerID\nFROM Orders\nWHERE OrderTotal > 500;",
"role": "assistant"
}
] | 654 |
[
{
"content": "Create a loop in JavaScript that prints the numbers from 1 to 10 in the console.",
"role": "user"
},
{
"content": "for (let i = 1; i <= 10; i++) {\n console.log(i);\n}",
"role": "assistant"
}
] | 655 |
[
{
"content": "Improve the following HTML structure.\n<div>\n<h2>Welcome!</h2>\n<p>This is my website.</p>\n</div>",
"role": "user"
},
{
"content": "<div>\n <h2>Welcome!</h2>\n <p>Hello and welcome to my website. Here, you can find all the information you need to know about me.</p>\n</div>",
"rol... | 656 |
[
{
"content": "Name three types of looping structures in Java.",
"role": "user"
},
{
"content": "The three types of looping structures in Java are for-loops, while-loops, and do-while loops.",
"role": "assistant"
}
] | 657 |
[
{
"content": "What is a callback function in JavaScript?",
"role": "user"
},
{
"content": "A callback function in JavaScript is a function that is passed as an argument to another function and is executed after the outer function has finished executing.",
"role": "assistant"
}
] | 658 |
[
{
"content": "Augment the following HTML structure to include a link to a CSS document.\n<head>\n <meta charset=\"UTF-8\">\n <title>My Webpage</title>\n</head>",
"role": "user"
},
{
"content": "<head>\n <meta charset=\"UTF-8\">\n <title>My Webpage</title>\n <link rel=\"stylesheet\" type=\"text/css\"... | 659 |
[
{
"content": "Explain in simple terms what is a tree structure in data structures.",
"role": "user"
},
{
"content": "A tree structure in data structures is a hierarchical structure composed of a root node connected to one or more nodes each of which is connected to one or more other nodes. It is a n... | 660 |
[
{
"content": "Write code to retrieve data from a given MySQL table.\nTable Name: Books",
"role": "user"
},
{
"content": "SELECT * FROM Books;",
"role": "assistant"
}
] | 661 |
[
{
"content": "Calculate the factorial of a given number.\nThe number is 7",
"role": "user"
},
{
"content": "5040",
"role": "assistant"
}
] | 662 |
[
{
"content": "Create a Linked List in C++.",
"role": "user"
},
{
"content": "// create a struct to represent a node\nstruct node \n{ \n int data; \n struct node* next; \n}; \n \n// function to insert an element in the Linked List \nvoid push(struct node** head_ref, int newdata) \n{ \n // a... | 663 |
[
{
"content": "Output the even numbers between 0 and 10.",
"role": "user"
},
{
"content": "2, 4, 6, 8, 10",
"role": "assistant"
}
] | 664 |
[
{
"content": "Write a query to display the average age of the students.\nTable Name: Students",
"role": "user"
},
{
"content": "SELECT AVG(Age) FROM Students;",
"role": "assistant"
}
] | 665 |
[
{
"content": "Compare two strings to determine if they are equal or not.\nString1: \"Hello World\"\nString2: \"Hello World\"",
"role": "user"
},
{
"content": "true",
"role": "assistant"
}
] | 666 |
[
{
"content": "Create a function to collect all the alphabets from a given string.\nThe string is \"My name is John!\"",
"role": "user"
},
{
"content": "//Function to collect all the alphabets\nfunction getAlphabets(str) {\n const result = [];\n for(let i=0; i < str.length; i++) {\n if(str[i].ma... | 667 |
[
{
"content": "Write a query to retrieve all the customer names from an orders table.\nTable Name: Orders",
"role": "user"
},
{
"content": "SELECT CustomerName FROM Orders;",
"role": "assistant"
}
] | 668 |
[
{
"content": "Obtain the type of the data in the given code.\nlet number = 10;",
"role": "user"
},
{
"content": "number is of type number.",
"role": "assistant"
}
] | 669 |
[
{
"content": "Create an array of the numbers from 1 to 10.",
"role": "user"
},
{
"content": "let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];",
"role": "assistant"
}
] | 670 |
[
{
"content": "Design a webpage with a given template.\nTemplate: Pink and Purple with three-column layout",
"role": "user"
},
{
"content": "<html>\n<head>\n <title>Pink and Purple Layout</title>\n <style>\n body {\n background-color: pink;\n }\n #container {\n display: flex;\n ... | 671 |
[
{
"content": "Calculate the circumference of a circle.\nRadius: 3",
"role": "user"
},
{
"content": "18.85",
"role": "assistant"
}
] | 672 |
[
{
"content": "Create a Python program to generate the Fibonacci series between 0 and 10.",
"role": "user"
},
{
"content": "def FibonacciSequence():\n a, b = 0, 1\n for _ in range(10):\n yield a\n a, b = b, a + b\n\nfor num in FibonacciSequence():\n print(num)",
"role": "assistant"
}
] | 673 |
[
{
"content": "Generate a set of five English words starting with the letter \"P\".",
"role": "user"
},
{
"content": "panther, plane, purple, parking, planet",
"role": "assistant"
}
] | 674 |
[
{
"content": "Given a list of numbers, extend the list such that it contains the square of the elements present in the list.\nnumbers = [1,2,3]",
"role": "user"
},
{
"content": "numbers = [1,2,3,1,4,9]",
"role": "assistant"
}
] | 675 |
[
{
"content": "Append a string \"Welcome to the party\" at the end of the provided array.\nwords = [\"Hello\", \"there\"]",
"role": "user"
},
{
"content": "words = [\"Hello\", \"there\", \"Welcome to the party\"]",
"role": "assistant"
}
] | 676 |
[
{
"content": "Write an SQL query to get the sum of the values in a column.\ntableName: myTable\ncolumnName: myColumn",
"role": "user"
},
{
"content": "SELECT SUM(myColumn) FROM myTable",
"role": "assistant"
}
] | 677 |
[
{
"content": "Create a CSS rule to set the body's font size to 12px.",
"role": "user"
},
{
"content": "body {\n font-size: 12px;\n}",
"role": "assistant"
}
] | 678 |
[
{
"content": "Filter the provided array by returning only even numbers.\nnumbers = [1, 2, 3, 4, 5]",
"role": "user"
},
{
"content": "numbers = [2, 4]",
"role": "assistant"
}
] | 679 |
[
{
"content": "Reorganize the provided data into an HTML table.\nstudents = [\n {name: 'John', age: 23},\n {name: 'Sarah', age: 26 },\n]",
"role": "user"
},
{
"content": "<table>\n <tr>\n <th>Name</th>\n <th>Age</th>\n </tr>\n <tr>\n <td>John</td>\n <td>23</td>\n </tr>\n <tr>\n <td>Sarah</td>\... | 680 |
[
{
"content": "Implement a stack data structure in Java.",
"role": "user"
},
{
"content": "// Stack class \nclass Stack \n{ \n static final int MAX = 1000; \n int top; \n int a[] = new int[MAX]; // Maximum size of Stack \n \n boolean isEmpty() \n { \n return (top < 0); \n } ... | 681 |
[
{
"content": "Write a JavaScript program to replace all the vowels in a given string with '*'.",
"role": "user"
},
{
"content": "function replaceVowels(str) {\n return str.replace(/[aeiou]/gi, '*');\n}",
"role": "assistant"
}
] | 682 |
[
{
"content": "Create a Java class that prints the Fibonacci sequence between 0 and 10.",
"role": "user"
},
{
"content": "public class Fibonacci {\n\n public static void main(String[] args) {\n printFibonacci();\n }\n\n public static void printFibonacci() {\n int n1 = 0;\n int n2 = 1;\n ... | 683 |
[
{
"content": "Make sure the following code runs without errors.\ndef calculate_sum(numbers):\n total = 0\n for number in numbers\n total += number\n return total",
"role": "user"
},
{
"content": "def calculate_sum(numbers):\n total = 0\n for number in numbers:\n ... | 684 |
[
{
"content": "Incorporate the following change in the given code.\ndef calculate_area(base, height):\n area = base*height\n area = float(area)\nChange: Calculate area of the triangle in square meters.",
"role": "user"
},
{
"content": "def calculate_area(base, height):\n area = 0.5*base*heig... | 685 |
[
{
"content": "Create a Python function which takes an array and returns true if the array contains all unique values.\narray = [1, 2, 3, 2]",
"role": "user"
},
{
"content": "\"\"\"\nCreate a Python function which takes an array and returns \ntrue if the array contains all unique values\n\"\"\"\n\nde... | 686 |
[
{
"content": "Write a code to get the value of pi (to 6 decimal places) using mathematical methods.",
"role": "user"
},
{
"content": "\"\"\"\nCalculate the value of pi using mathematical methods\n\"\"\"\n\ndef calculate_pi():\n pi = 0 \n n = 1000\n for n in range(n):\n pi += ((-1)**... | 687 |
[
{
"content": "Visualize the following on a line chart.\nData points = [12, 13, 19, 20, 25]",
"role": "user"
},
{
"content": "import matplotlib.pyplot as plt\n\ndata_points = [12, 13, 19, 20, 25]\n\nplt.plot(data_points)\nplt.ylabel(\"data points\")\nplt.xlabel(\"index\")\nplt.title(\"Line chart of d... | 688 |
[
{
"content": "Implement a binary search on the given array.\nArray = [1, 4, 5, 6, 7, 9]",
"role": "user"
},
{
"content": "\"\"\"\nImplement a binary search on a given array\n\"\"\"\n\ndef binary_search(arr, element):\n start = 0\n end = len(arr) - 1\n while start <= end:\n mid = (sta... | 689 |
[
{
"content": "Change the following code so that it prints the list elements in reverse order.\narr = [1, 2, 3, 4, 5]\n\nfor x in arr:\n print(x)",
"role": "user"
},
{
"content": "arr = [1, 2, 3, 4, 5]\n\nfor x in arr[::-1]:\n print(x)",
"role": "assistant"
}
] | 690 |
[
{
"content": "Consider the following program. Find out the output without running it.\nmy_list = [1, 1, 2, 3, 5, 8]\n\nfor x in my_list:\n if x%2 == 0:\n print(x)",
"role": "user"
},
{
"content": "2\n8",
"role": "assistant"
}
] | 691 |
[
{
"content": "Create a function that takes a string and returns a new string with each character capitalized.\nString = \"hello!\"",
"role": "user"
},
{
"content": "\"\"\"\nCreate a function that takes a string and returns a new string with each character capitalized\n\"\"\"\n\ndef capitalize(string... | 692 |
[
{
"content": "Show how this array could be sorted using the insertion sort algorithm.\n[3, 4, 8, 1, 5]",
"role": "user"
},
{
"content": "// Initial Array\n[3, 4, 8, 1, 5]\n\n// 1st Pass\n[3, 4, 8, 1, 5] // Move 8 to the left\n[3, 4, 1, 8, 5]\n\n// 2nd Pass\n[3, 4, 1, 8, 5] // Move 4 to the left\n[3,... | 693 |
[
{
"content": "Write a short JavaScript code snippet to detect a browser language and display a response message in that particular language.",
"role": "user"
},
{
"content": "// get the current browser language\nvar language = navigator.language || navigator.userLanguage;\n\nif (language === \"en\")... | 694 |
[
{
"content": "Describe how to use the following code to sort an array in ascending order.\nfunction bubbleSort(arr) {\n let len = arr.length;\n for (let i = 0; i < len; i++) {\n for (let j = 0; j < len; j++) {\n if (arr[j] > arr[j+1]) {\n let temp = arr[j];\n ... | 695 |
[
{
"content": "Create an integer array using Java and sort it using the bubble sort algorithm.",
"role": "user"
},
{
"content": "// Create an integer array\nint[] array = {4, 2, 6, 1, 3};\n\n// Sort the array using the bubbleSort function\nbubbleSort(array);\n\n// Write a function to implement the bu... | 696 |
[
{
"content": "Describe how to add an element in a linked list in Python.",
"role": "user"
},
{
"content": "// To add an element in a linked list in Python:\n// 1. Create a new node containing the value to be added\n// 2. Set the \"next\" attribute of the new node to point to the current head node\n/... | 697 |
[
{
"content": "Explain how to implement a heap sort algorithm in Java.",
"role": "user"
},
{
"content": "// To implement a heap sort algorithm in Java:\n// 1. Build a min heap from the input data.\n// 2. At the top of the heap, obtain the minimum element.\n// 3. Exchange the minimum element with the ... | 698 |
[
{
"content": "Suggest a Python code to parse an XML document.",
"role": "user"
},
{
"content": "# Parse an XML document using Python\nimport xml.etree.ElementTree as ET\n\n# load the XML document\ntree = ET.parse('document.xml')\n# get the root element\nroot = tree.getroot()\n# loop through all the ... | 699 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.