messages listlengths 2 2 | conversation_id int64 0 20k |
|---|---|
[
{
"content": "Write the SQL query to delete all records from the table 'Customer'",
"role": "user"
},
{
"content": "DELETE FROM Customer;",
"role": "assistant"
}
] | 500 |
[
{
"content": "Parse the following JSON and extract the value of the variable 'price'.\n`{\n \"item\": \"Shoes\",\n \"price\": 125\n}`",
"role": "user"
},
{
"content": "import json \n\n# parse the JSON string\ndata = json.loads(input_json)\n\n# extract the value of the price variable\nprice = data['p... | 501 |
[
{
"content": "Write a Python program to print out the Fibonacci sequence up to 20 numbers",
"role": "user"
},
{
"content": "def fibonacci(n): \n a = 0\n b = 1\n if n < 0: \n print(\"Incorrect input\") \n elif n == 0: \n return a \n elif n == 1: \n return b \n e... | 502 |
[
{
"content": "Correct the following HTML code to remove mistakes and indentation errors\n`<html><head><title>My Site</title></head>\n <body>\n <h1>Welcome!</h1><p>My website\n </body>\n </html>`",
"role": "user"
},
{
"content": "<html>\n <head>\n <title>My Site</title>\n </head>\n <body>\n ... | 503 |
[
{
"content": "Calculate the sum of the numbers in the array [1, 5, 7, 10]",
"role": "user"
},
{
"content": "# Define the array\narr = [1, 5, 7, 10]\n\n# Calculate the sum\nsum = sum(arr)\n\n# Print the result\nprint(\"The sum of the numbers in the array is \" + str(sum) + \".\")",
"role": "assis... | 504 |
[
{
"content": "Update the following code to use a while loop instead of a for loop\n`# Define an array\narr = [1, 2, 3, 4]\n\n# Iterate over the array and print each element\nfor i in arr:\n print(i)`",
"role": "user"
},
{
"content": "# Define an array\narr = [1, 2, 3, 4]\n\n# Initialize the index... | 505 |
[
{
"content": "Write a code to implement Selection Sort in Java",
"role": "user"
},
{
"content": "public class SelectionSort {\n public static void sort(int[] arr) {\n int n = arr.length;\n \n // One by one move boundary of unsorted subarray\n for (int i = 0; i < n-1; i++)\n ... | 506 |
[
{
"content": "Write a query to find out the maximum salary earned by an employee",
"role": "user"
},
{
"content": "SELECT MAX(salary)\nFROM Employees;",
"role": "assistant"
}
] | 507 |
[
{
"content": "Create a class Employee with constructor to initialize the instance variables _name and _age",
"role": "user"
},
{
"content": "class Employee {\n \n private String _name;\n private int _age;\n \n public Employee(String name, int age) {\n this._name = name;\n ... | 508 |
[
{
"content": "Design a function to remove duplicates from an array",
"role": "user"
},
{
"content": "def remove_duplicates(arr):\n # Stores the unique elements\n unique = []\n\n # Iterate through the array\n for elem in arr:\n # If the element is not already in the unique list\n ... | 509 |
[
{
"content": "Write a C++ code to find the greatest common divisor of two integers",
"role": "user"
},
{
"content": "#include<iostream>\n\nusing namespace std;\n\nint gcd(int first, int second) {\n // Base case\n if (second == 0)\n return first;\n \n return gcd(second, first % sec... | 510 |
[
{
"content": "Given a list of numbers, write a function to find the largest value in the list.\nlst = [1, 5, 9, 12, 8]",
"role": "user"
},
{
"content": "def get_largest_value(lst):\n max_value = lst[0]\n for num in lst:\n if num > max_value:\n max_value = num\n return max_... | 511 |
[
{
"content": "Create an algorithm to sort a list of numbers in ascending order.\nlst = [2, 5, 1, 7, 4]",
"role": "user"
},
{
"content": "def sort_list_ascending(lst):\n # Traverse through all array elements \n for i in range(len(lst)): \n \n # Find the minimum element in remaining \n ... | 512 |
[
{
"content": "Given an array, write a program that checks if any two numbers sum to 0.\narr = [-3, -2, 1, 2, 3]",
"role": "user"
},
{
"content": "def check_if_sum_zero(arr): \n for i in range(len(arr)): \n for j in range(i + 1, len(arr)): \n if (arr[i] + arr[j] == 0): \n ... | 513 |
[
{
"content": "Create a program to generate an XOR linked list.",
"role": "user"
},
{
"content": "class Node: \n def __init__(self, data): \n self.data = data \n self.npx = None\n \nclass XORLinkedList: \n def __init__(self): \n self.head = None\n \n def add(self, item... | 514 |
[
{
"content": "Given a list of strings, write a program to sort the strings in alphabetical order.\nlst = [\"apple\", \"orange\", \"grapes\"]",
"role": "user"
},
{
"content": "def sort_in_alphabetical_order(lst): \n lst.sort()\n return lst\n\nprint(sort_in_alphabetical_order([\"apple\", \"orang... | 515 |
[
{
"content": "Create a function to generate the nth term in the Fibonacci sequence.\nn = 3",
"role": "user"
},
{
"content": "def get_fib_term(n): \n if n <= 1: \n return n \n else: \n return get_fib_term(n-1) + get_fib_term(n-2)\n \nprint(get_fib_term(3))",
"role": "assistan... | 516 |
[
{
"content": "Calculate the mean of a list of numbers.\nlst = [1, 2, 3, 4, 5]",
"role": "user"
},
{
"content": "def calculate_mean(lst):\n return sum(lst) / len(lst)\n\nprint(calculate_mean([1, 2, 3, 4, 5]))",
"role": "assistant"
}
] | 517 |
[
{
"content": "Sum all the prices in the list of dictionaries and output the result as an integer.\nlist_of_dictionaries = [{\"price\": 5}, {\"price\": 7}, {\"price\": 9}]",
"role": "user"
},
{
"content": "21",
"role": "assistant"
}
] | 518 |
[
{
"content": "Edit the original code snippet so that it prints in the correct syntax for a Python 3 script.\n#!/usr/bin/python\nprint \"Hello, World!\"",
"role": "user"
},
{
"content": "#!/usr/bin/python\nprint(\"Hello, World!\")",
"role": "assistant"
}
] | 519 |
[
{
"content": "Write a function in JavaScript that takes an integer n and returns the nth Fibonacci number.",
"role": "user"
},
{
"content": "function Fibonacci(n) { \n if (n <= 1) return n; \n return Fibonacci(n-1) + Fibonacci(n-2); \n}",
"role": "assistant"
}
] | 520 |
[
{
"content": "Given the following object, write a function in JavaScript to count the occurrences of each character in the object's values.\nobj = {\n \"name\": \"John Doe\"\n}",
"role": "user"
},
{
"content": "function countOccurences(obj) {\n let result = {};\n for (let value of Object.value... | 521 |
[
{
"content": "Using the given list, create a function in Python that classifies each number as odd or even.\nlst = [1, 2, 6, 8, 4]",
"role": "user"
},
{
"content": "def classifyList(lst):\n result = []\n for num in lst: \n if num % 2 == 0: \n result.append('even')\n el... | 522 |
[
{
"content": "Write a Java program that takes two strings as inputs and checks if one string is a rotation of the other.",
"role": "user"
},
{
"content": "import java.util.Arrays;\n \nclass GFG {\n \n // Function to check if two strings are \n // rotations of each other or not\n static bool... | 523 |
[
{
"content": "Given the following array of dictionaries, write a function in Python to find and return the longest common prefix in the keys of dictionaries.\narr_of_dictionaries = [\n {\n \"name\": \"John Doe\",\n \"country\": \"United States\"\n },\n {\n \"name\": \"Jane Doe\",\n... | 524 |
[
{
"content": "Write a function in Java that takes a string consisting of brackets and output true if the brackets are properly nested, else output false.",
"role": "user"
},
{
"content": "public static boolean isBalanced(String str) \n{ \n if(str.length() == 0) \n return true; \n \n ... | 525 |
[
{
"content": "Given a string and a set of delimiters, write a function in JavaScript to split the string.\nstring = \"Hello, world!\"\ndelimiters = [\" \", \",\", \"-\", \"!\"]",
"role": "user"
},
{
"content": "function splitStringWithDelimiters (string, delimiters) { \n let result = []; \n let s ... | 526 |
[
{
"content": "Create an array in Java with 10 floating-point values and output the average of these values.",
"role": "user"
},
{
"content": "// Create an array \nfloat arr[] = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.1};\n\n// Calculate average \nfloat sum = 0;\nfor (int i = 0; i < 10; i++)... | 527 |
[
{
"content": "Find the power of a number using an iterative approach in Java.",
"role": "user"
},
{
"content": "public static int power(int base, int exp) \n{ \n int result = 1; \n while (exp != 0) \n { \n result *= base; \n --exp; \n } \n return result; \n}",
"role"... | 528 |
[
{
"content": "Write a function in Python that takes a string and a set of characters as inputs and removes all characters in the string that are in the set.\nstring = \"Hello, world!\"\ncharset = [\"o\", \"!\"]",
"role": "user"
},
{
"content": "def removeChars(string, charset):\n\tresult = \"\"\n\tf... | 529 |
[
{
"content": "Create a program to count the total characters in a string.",
"role": "user"
},
{
"content": "def count_string_characters(string):\n return len(string)",
"role": "assistant"
}
] | 530 |
[
{
"content": "Make a code to determine whether a given number is prime or not.",
"role": "user"
},
{
"content": "def is_prime(x):\n for i in range(2,int(x**0.5)+1):\n if x % i == 0:\n return False\n return True",
"role": "assistant"
}
] | 531 |
[
{
"content": "Create a code that sorts element in an array.",
"role": "user"
},
{
"content": "def sort_elements(arr):\n return sorted(arr)",
"role": "assistant"
}
] | 532 |
[
{
"content": "Develop a function to swap the position of two elements in an array.",
"role": "user"
},
{
"content": "def swap_elements(arr, i, j):\n arr[i], arr[j] = arr[j], arr[i]\n return arr",
"role": "assistant"
}
] | 533 |
[
{
"content": "Create function to return the cube of a number.",
"role": "user"
},
{
"content": "def cube_number(x):\n return x**3",
"role": "assistant"
}
] | 534 |
[
{
"content": "Create a function that takes a number and returns the sum of all its divisors.",
"role": "user"
},
{
"content": "def get_divisor_sum(n):\n divisor_sum = 0\n for i in range(1, n//2 + 1):\n if n % i == 0:\n divisor_sum += i\n return divisor_sum",
"role": "a... | 535 |
[
{
"content": "Write an SQL query to select all entries from the \"Users\" table.",
"role": "user"
},
{
"content": "SELECT * FROM Users;",
"role": "assistant"
}
] | 536 |
[
{
"content": "Create a loop to print hello world 5 times.",
"role": "user"
},
{
"content": "for (int i = 0; i < 5; i++){ \n System.out.println(\"Hello World!\"); \n}",
"role": "assistant"
}
] | 537 |
[
{
"content": "Create a HTML page with 3 sections, using div tags.",
"role": "user"
},
{
"content": "<div>\n <div id=\"section1\"> Section 1... </div> \n <div id=\"section2\"> Section 2... </div> \n <div id=\"section3\"> Section 3... </div>\n</div>",
"role": "assistant"
}
] | 538 |
[
{
"content": "Create a function to check whether a number entered is prime or not.",
"role": "user"
},
{
"content": "def is_prime(number):\n # If given number is greater than 1\n if number > 1:\n # Iterate from 2 to n / 2\n for i in range(2, number//2):\n # If num is divisi... | 539 |
[
{
"content": "Sort a list of 5 numbers in descending order.\n[123, 45, 287, 398, 135]",
"role": "user"
},
{
"content": "[398, 287, 135, 123, 45]",
"role": "assistant"
}
] | 540 |
[
{
"content": "Using an object-oriented programming language, create a class that has two methods - one to calculate the area of a circle and another to calculate the circumference.",
"role": "user"
},
{
"content": "class Circle():\n def __init__(self, radius):\n self.radius = radius\n d... | 541 |
[
{
"content": "Concisely describe how a Linked List works.",
"role": "user"
},
{
"content": "A linked list is a linear data structure in which each node is comprised of a data element as well as a pointer to the next node in the list. This allows it to form a chain, with each node pointing to the nex... | 542 |
[
{
"content": "Find the index of the number 23 in the given array.\n[78, 82, 6, 23, 77, 57, 88]",
"role": "user"
},
{
"content": "3",
"role": "assistant"
}
] | 543 |
[
{
"content": "Write an SQL query to display all the employee names in the 'students' table.",
"role": "user"
},
{
"content": "SELECT name FROM students;",
"role": "assistant"
}
] | 544 |
[
{
"content": "Convert the given string to uppercase.\nHello World",
"role": "user"
},
{
"content": "HELLO WORLD",
"role": "assistant"
}
] | 545 |
[
{
"content": "Create a program in Python that calculates the average of numbers in a list.\n[9, 5, 10, 12]",
"role": "user"
},
{
"content": "def average(numbers):\n return sum(numbers) / len(numbers)\n\nprint(average([9, 5, 10, 12])) # Output: 9.5",
"role": "assistant"
}
] | 546 |
[
{
"content": "Use JavaScript to filter an array of numbers such that only even numbers are returned.\n[1, 4, 6, 7, 8, 3, 10]",
"role": "user"
},
{
"content": "const arr = [1, 4, 6, 7, 8, 3, 10];\n\nconst evenArr = arr.filter(num => num % 2 == 0);\n\nconsole.log(evenArr); // Output: [4, 6, 8, 10]",
... | 547 |
[
{
"content": "Write a C++ program that prints out the prime numbers up to 100.",
"role": "user"
},
{
"content": "#include <iostream> \nusing namespace std; \n \nvoid printPrimeNumber(int n) \n{ \n int flag; \n \n for (int i = 2; i <=n; i++) { \n flag = 0; \n for (int j = 2; j <... | 548 |
[
{
"content": "Create a JavaScript function that takes in two parameters and returns their sum.",
"role": "user"
},
{
"content": "function sum(num1, num2) {\n return num1 + num2;\n}",
"role": "assistant"
}
] | 549 |
[
{
"content": "Create a class in Ruby that prints a message when instantiated.",
"role": "user"
},
{
"content": "class MyClass\n def initialize\n puts \"Welcome to MyClass!\"\n end\nend",
"role": "assistant"
}
] | 550 |
[
{
"content": "Write an SQL query that selects the maximum price from all products.\nTable Name: Products\nColumns: Name (varchar), Price (decimal)",
"role": "user"
},
{
"content": "SELECT MAX(Price) FROM Products;",
"role": "assistant"
}
] | 551 |
[
{
"content": "Create a binary search tree in JavaScript.",
"role": "user"
},
{
"content": "class Node { \n constructor(data) \n { \n this.data = data; \n this.left = null; \n this.right = null; \n } \n} \n \nclass BinarySearchTree { \n constructor() \n { \n this.root = null; \n } ... | 552 |
[
{
"content": "Suppose there is an array of numbers. Write a Java program to sort the array in ascending order.\n[3,8,5,1,2,6,4]",
"role": "user"
},
{
"content": "public class SortAscending { \n public static void main(String[] args) \n {\n int[] numbers = {3,8,5,1,2,6,4};\n int t... | 553 |
[
{
"content": "Modify the above program to sort the array in descending order.\n[3,8,5,1,2,6,4]",
"role": "user"
},
{
"content": "public class SortDescending { \n public static void main(String[] args) \n {\n int[] numbers = {3,8,5,1,2,6,4};\n int temp = 0;\n for (int i = 0... | 554 |
[
{
"content": "Create an HTML form with two input boxes and a submit button.",
"role": "user"
},
{
"content": "<form>\n <label>Name: </label>\n <input type=\"text\" name=\"name\"><br>\n <label>Age: </label>\n <input type=\"number\" name=\"age\"><br>\n <input type=\"submit\" value=\"Submit\"... | 555 |
[
{
"content": "Edit the above PHP function so that it also checks if a given number is prime.",
"role": "user"
},
{
"content": "function isPrime($n) {\n if ($n == 1) {\n return false;\n } \n elseif ($n == 2) {\n return true;\n } \n else {\n for ($i = 2; $i <= sqrt($n); $i++) {\n if... | 556 |
[
{
"content": "Create a Python function to parse a string and remove all special characters.",
"role": "user"
},
{
"content": "import re\n\ndef remove_special_chars(s):\n return re.sub(r'[^\\w\\s]','', s)",
"role": "assistant"
}
] | 557 |
[
{
"content": "Modify the function to also remove all whitespace from the string.",
"role": "user"
},
{
"content": "import re\n\ndef remove_special_chars_and_whitespace(s):\n return re.sub(r'\\s','', re.sub(r'[^\\w\\s]','', s))",
"role": "assistant"
}
] | 558 |
[
{
"content": "Create an object in JavaScript that performs a task given a condition.",
"role": "user"
},
{
"content": "const myObject = {\n doTask: (condition) => {\n if(condition) {\n // code to perform the task\n } \n }\n}",
"role": "assistant"
}
] | 559 |
[
{
"content": "For the following list, print out the second element.\nlist = [\"apple\", \"banana\", \"cherry\"]",
"role": "user"
},
{
"content": "second_element = list[1]\nprint(second_element) # prints banana",
"role": "assistant"
}
] | 560 |
[
{
"content": "What is the next output when this code is executed?\ni = 0 \nwhile (i < 5): \n print(i, sep = \", \")\n i += 1",
"role": "user"
},
{
"content": "0, 1, 2, 3, 4",
"role": "assistant"
}
] | 561 |
[
{
"content": "Write a code to find the square of the first n numbers.",
"role": "user"
},
{
"content": "def square_of_first_n_number(n):\n \"\"\"Find the square of the first n numbers\"\"\"\n \n # Initialize an empty list\n squares = []\n\n # Iterate to the first n numbers\n for i ... | 562 |
[
{
"content": "Formulate an SQL query to make this table:\nTable: books\n\nbook_id | book_title | book_edition\n------------------------",
"role": "user"
},
{
"content": "CREATE TABLE books (\n book_id INTEGER PRIMARY KEY,\n book_title VARCHAR(50),\n book_edition VARCHAR(50)\n);",
"role"... | 563 |
[
{
"content": "Reverse the following String.\nString = \"Hello World!\"",
"role": "user"
},
{
"content": "rev_string = String[::-1] \nprint(rev_string) # prints \"!dlroW olleH\"",
"role": "assistant"
}
] | 564 |
[
{
"content": "Given a list, write code to convert the list into a dictionary.\nlist1 = [\"John\", \"Doe\", 23]",
"role": "user"
},
{
"content": "dict1 = dict(zip(['name', 'surname', 'age'], list1))\nprint(dict1) # prints {'name': 'John', 'surname': 'Doe', 'age': 23}",
"role": "assistant"
}
] | 565 |
[
{
"content": "Given a two-dimensional array, write a code to sum the values in each row.\nA = [[1, 2, 3], \n [4, 5, 6], \n [7, 8, 9]]",
"role": "user"
},
{
"content": "row_sum = []\nfor row in A:\n row_sum.append(sum(row))\n \nprint(row_sum) # prints [6, 15, 24]",
"role": "assistan... | 566 |
[
{
"content": "Construct a for loop that will loop over the string \"Hello World\".",
"role": "user"
},
{
"content": "for letter in \"Hello World\":\n print(letter)",
"role": "assistant"
}
] | 567 |
[
{
"content": "Write a code to find the missing number in the given array.\nA = [1, 2, 3, 4, 6, 7, 8]",
"role": "user"
},
{
"content": "# Create a set from the array\nA_set = set(A)\n\n# Determine the max value\nmax_val = max(A_set)\n\n# Find the missing number\nmissing_number = max_val - sum(A_set)\... | 568 |
[
{
"content": "What would be the resulting string after executing this code?\na = \"Hello\"\nb = \"World\"\n\nc = a + \" \" + b\n\nc = f\"{c}!\"",
"role": "user"
},
{
"content": "c = \"Hello World!\"",
"role": "assistant"
}
] | 569 |
[
{
"content": "Write a code to print out all the prime numbers between 2 and 10.",
"role": "user"
},
{
"content": "# initialize an empty list to store prime numbers\nprime_numbers = []\n\n# Iterate over the range from 2 to 10\nfor num in range(2, 11):\n cnt = 0\n # check if the number is divisi... | 570 |
[
{
"content": "Write a function to remove all duplicate elements in an array.\ndata = [1, 2, 3, 2, 4, 5]",
"role": "user"
},
{
"content": "def remove_duplicates(data):\n \"\"\"Remove all duplicate elements in an array\"\"\"\n \n # Initialize an empty list\n unique_data = []\n\n # Itera... | 571 |
[
{
"content": "What will happen when the following code is executed?\na_list = [1, 2, 3, 4, 5]\n\nfor i in a_list:\n a_list.append(i + 6)\n\nprint(a_list)",
"role": "user"
},
{
"content": "[1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12]",
"role": "assistant"
}
] | 572 |
[
{
"content": "What data type should you use to store a list like [4, 7, 2] in a Python variable?",
"role": "user"
},
{
"content": "The data type you should use to store a list like [4, 7, 2] in a Python variable is a list. The list type is specified using square brackets when declaring the variable.... | 573 |
[
{
"content": "Rearrange the following list of numbers in an ascending order.\n[9, 5, 8, 2, 4]",
"role": "user"
},
{
"content": "[2, 4, 5, 8, 9]",
"role": "assistant"
}
] | 574 |
[
{
"content": "Improve the following code to handle an input which is an empty list.\ndef check_even(arr):\n if arr == []:\n return \"The list is empty!\"\n else:\n return all(x % 2 == 0 for x in arr)",
"role": "user"
},
{
"content": "def check_even(arr):\n if arr == []:\n ... | 575 |
[
{
"content": "How much would you substract 5 to 101?",
"role": "user"
},
{
"content": "96",
"role": "assistant"
}
] | 576 |
[
{
"content": "Generate a list of odd numbers from 80 to 100.",
"role": "user"
},
{
"content": "[81, 83, 85, 87, 89, 91, 93, 95, 97, 99]",
"role": "assistant"
}
] | 577 |
[
{
"content": "Modify the following code to handle an input which is a negative number.\ndef power_func(number):\n if number >= 0:\n return number**2",
"role": "user"
},
{
"content": "def power_func(number):\n if number < 0:\n return \"Invalid input!\"\n else:\n return n... | 578 |
[
{
"content": "Edit the following code snippet to add an error handling that allows the function to return an appropriate message when an invalid input is received.\ndef factorial(n):\n \tif n == 0:\n \t return 1\n\telse:\n \t return n * factorial(n-1)",
"role": "user"
},
{
"content": "def fac... | 579 |
[
{
"content": "Given the following list, extract the item at index 2.\nmy_list = [\"apple\", \"banana\", \"mango\", \"grapes\"]",
"role": "user"
},
{
"content": "mango",
"role": "assistant"
}
] | 580 |
[
{
"content": "Write a Python program to find out the common items from two given arrays.\narr1 = [1, 2, 3, 5, 7 ]\narr2 = [2, 3, 5, 6, 7]",
"role": "user"
},
{
"content": "common_items = []\n\nfor item in arr1:\n if item in arr2:\n common_items.append(item)\n\nprint(common_items) # Output: [2, ... | 581 |
[
{
"content": "Write a Python function to check whether a string has all unique characters.",
"role": "user"
},
{
"content": "def all_unique(string): \n # loops through each character in string \n for char in string: \n \n # if character appears more than once, \n # return False \n if str... | 582 |
[
{
"content": "Given the following dictionary, change the value of the key \"a\" to \"apples\".\nmy_dict = {\"a\": \"bananas\", \"b\": \"pears\"}",
"role": "user"
},
{
"content": "my_dict = {\"a\": \"apples\", \"b\": \"pears\"}",
"role": "assistant"
}
] | 583 |
[
{
"content": "Rewrite the following code so it can take a list as input instead of an integer.\ndef list_sum(num):\n total = 0\n for x in range(num):\n total += x\n return total",
"role": "user"
},
{
"content": "def list_sum(input_list):\n total = 0\n for item in input_list:\n ... | 584 |
[
{
"content": "Design a program to compare two sorted lists and returning list with the common elements.\nlist_one=[5, 10, 15, 20, 25]\nlist_two=[15, 17, 20, 22, 25, 27]",
"role": "user"
},
{
"content": "def compare_list(list_one, list_two):\n common_list = []\n i, j = 0, 0\n while (i < len(... | 585 |
[
{
"content": "Design a program to flatten a given list.\n[[1, 2, 3], [4, 5, 6], [7, 8, 9]]",
"role": "user"
},
{
"content": "def flatten_list(lst):\n res = []\n for l in lst:\n for i in l:\n res.append(i)\n return res",
"role": "assistant"
}
] | 586 |
[
{
"content": "Write a script to determine whether an element is present in a given array.\nGiven array: [1,2,5,7]\nNumber to find: 5",
"role": "user"
},
{
"content": "def element_in_array(lst, n): \n for i in range(len(lst)): \n if n == lst[i]: \n return True \n return False"... | 587 |
[
{
"content": "Write a script to generate the Fibonacci sequence up to a certain number.\nNumber of elements to generate: 10",
"role": "user"
},
{
"content": "def fibonacci_sequence(n):\n if n == 0:\n return []\n elif n == 1:\n return [1]\n else:\n lst = [1, 1]\n ... | 588 |
[
{
"content": "Design a program to find the intersection of two given arrays.\nlist_one=[5, 10, 15, 20, 25]\nlist_two=[15, 17, 20, 22, 25, 27]",
"role": "user"
},
{
"content": "def intersection(list_one, list_two):\n lst = []\n for i in list_one:\n if i in list_two:\n lst.appe... | 589 |
[
{
"content": "Write a script to delete an element from an array given its index.\nGiven array: [1, 2, 3, 4]\nIndex of element to delete: 1",
"role": "user"
},
{
"content": "def delete_element(lst, index):\n del lst[index]\n return lst",
"role": "assistant"
}
] | 590 |
[
{
"content": "Design a program to find the nth Fibonacci number.\nn: 10",
"role": "user"
},
{
"content": "def nth_fibonacci(n):\n if n == 0 or n == 1:\n return 1\n else:\n n1, n2 = 1, 1\n for i in range(2, n):\n n1, n2 = n2, n1 + n2\n return n2",
"rol... | 591 |
[
{
"content": "Design a program to find the occurrence of a given character in a given string.\nGiven string: \"Hello World!\"\nCharacter to find: o",
"role": "user"
},
{
"content": "def occurance_count(str, char):\n count = 0\n for c in str:\n if c == char:\n count += 1\n ... | 592 |
[
{
"content": "Generate a function to multiply two integers.",
"role": "user"
},
{
"content": "def multiply_ints(x, y): \n return x * y",
"role": "assistant"
}
] | 593 |
[
{
"content": "Create a loop to iterate over characters in a given string.\nSample string s = \"Hello World\"",
"role": "user"
},
{
"content": "for char in s:\n print(char)",
"role": "assistant"
}
] | 594 |
[
{
"content": "Create an if-else statement to classify a given number into an even or an odd.",
"role": "user"
},
{
"content": "if (num % 2 == 0):\n print(\"Even\")\nelse:\n print(\"Odd\")",
"role": "assistant"
}
] | 595 |
[
{
"content": "Write a regular expression to validate a given string of IP addresses.",
"role": "user"
},
{
"content": "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$",
"role": "assistant"
}
] | 596 |
[
{
"content": "Create a project in random forest to learn the target variable given a set of predictor variables.\npredictor_vars = [\"age\", \"occupation\"]\ntarget_var = \"income\"",
"role": "user"
},
{
"content": "from sklearn.ensemble import RandomForestRegressor\n\n# Initialize the model\nmodel ... | 597 |
[
{
"content": "Use the back-propagation algorithm to learn the weights of a given neural network.",
"role": "user"
},
{
"content": "# Initialize weights with random values & weights\nweights = np.random.uniform(-1,1, (num_nodes, num_inputs))\nbias = np.random.uniform(-1,1, num_nodes)\n\n#Forward pass... | 598 |
[
{
"content": "Create a loop to traverse a given binary tree.",
"role": "user"
},
{
"content": "def traverse_tree(root):\n\n # Initialize the stack\n stack = [root]\n\n # traversal loop\n while stack:\n node = stack.pop()\n\n # Do something with the node\n ...\n\n ... | 599 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.