dataset
stringclasses
12 values
id
stringlengths
5
50
messages
listlengths
1
138
code_alpaca
code_alpaca_200
[ { "role": "user", "content": "Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a code to check whether two strings are anagrams or not.\n\n### Input:\nfirst = \"listen\"\ns...
code_alpaca
code_alpaca_201
[ { "role": "user", "content": "Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a code to delete all the vowels from a given string.\n\n### Input:\nstring = \"hello world\"\...
code_alpaca
code_alpaca_202
[ { "role": "user", "content": "Write a code to convert a given list of strings to uppercase.\n\nNow complete the following instance -\nInput: mylist = [\"hello\",\"world\"]\nOutput:" }, { "role": "assistant", "content": "\"\"\"\nWrite a code to convert a given list of strings to uppercase\n\"\"\"...
code_alpaca
code_alpaca_203
[ { "role": "user", "content": "Write a code to find the maximum in a given list of integers.\n\nmylist = [1,2,3,4,5]\n\n" }, { "role": "assistant", "content": "\"\"\"\nWrite a code to find the maximum in a given list of integers\n\"\"\"\n\n# List containing the elements\nmylist = [1,2,3,4,5]\n\n#...
code_alpaca
code_alpaca_204
[ { "role": "user", "content": "Write a code to generate the multiplication table of a given integer.\nInput: x = 5\nOutput:" }, { "role": "assistant", "content": "\"\"\"\nWrite a code to generate the multiplication table of a given integer\n\"\"\"\n\n# Number for which multiplication table will b...
code_alpaca
code_alpaca_205
[ { "role": "user", "content": "Write a code to merge two given lists of equal size.\nlist1 = [1,2,3]\nlist2 = [4,5,6]\n\n" }, { "role": "assistant", "content": "\"\"\"\nWrite a code to merge two given lists of equal size\n\"\"\"\n\n# Given lists\nlist1 = [1,2,3]\nlist2 = [4,5,6]\n\n# Initialising...
code_alpaca
code_alpaca_206
[ { "role": "user", "content": "Write a code to compute the mean of an input list of numbers.\n\nInput: mylist = [1,2,3,4,5]\n\nOutput:" }, { "role": "assistant", "content": "\"\"\"\nWrite a code to compute the mean of an input list of numbers\n\"\"\"\n\n# List containing the elements\nmylist = [1...
code_alpaca
code_alpaca_207
[ { "role": "user", "content": "Create a program to convert the input sentence to Pig Latin.\n\nI am a computer programmer\n\n" }, { "role": "assistant", "content": "\"\"\"\nCreate a program to convert the input sentence to Pig Latin.\n\"\"\"\n\ndef pig_latin(sentence):\n words = sentence.split...
code_alpaca
code_alpaca_208
[ { "role": "user", "content": "Create a program to write an overwriting if-else logic for the following switch statement\nswitch(a) {\n case 1: \n func1();\n break;\n case 2: \n func2();\n break;\n}\n" }, { "role": "assistant", "content": "\"\"\"\nCreate a program to write an overwr...
code_alpaca
code_alpaca_209
[ { "role": "user", "content": "Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a function that sorts the given list of numbers in descending order\n\n### Input:\n[1, 2, 3, ...
code_alpaca
code_alpaca_210
[ { "role": "user", "content": "Create a program to create a list of all the numbers from 1 to 10 which are divisible by 3\n" }, { "role": "assistant", "content": "\"\"\"\nCreate a program to create a list of all the numbers from 1 to 10 which are divisible by 3\n\"\"\"\n\ndef divisible_by_three()...
code_alpaca
code_alpaca_211
[ { "role": "user", "content": "You need to complete the following task:\n\nrewrite the following for-loop as a while-loop\n\nfor i in range(0, 5):\n print(i)\n\nAnswer:" }, { "role": "assistant", "content": "\"\"\"\nRewrite the following for-loop as a while-loop\n\"\"\"\n\ni = 0\nwhile i < 5:\...
code_alpaca
code_alpaca_212
[ { "role": "user", "content": "Create a program to compute the checksum of a given data packet\nInput: data_packet = [0xff, 0x0a, 0x1b, 0x3f]\nOutput:" }, { "role": "assistant", "content": "\"\"\"\nCreate a program to compute the checksum of a given data packet\n\"\"\"\n\ndef compute_checksum(dat...
code_alpaca
code_alpaca_213
[ { "role": "user", "content": "Create a program to parse a given string and return a dictionary with all the words and their frequency\n\nInput: \"this is a practice string to learn the parsing of strings\"\n\nOutput:" }, { "role": "assistant", "content": "\"\"\"\nCreate a program to parse a give...
code_alpaca
code_alpaca_214
[ { "role": "user", "content": "Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nCreate a program to classify whether the given number is even or odd\n\n### Input:\n5\n\n### Respon...
code_alpaca
code_alpaca_215
[ { "role": "user", "content": "Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nCreate a program to generate the sum of all the elements in a given list\n\n### Input:\n[1, 2, 3, 4...
code_alpaca
code_alpaca_216
[ { "role": "user", "content": "Create a program to find all the factors of a given number\n\nAdditional Context:\n24\n\nAnswer:" }, { "role": "assistant", "content": "\"\"\"\nCreate a program to find all the factors of a given number \n\"\"\"\n\ndef find_factors(num):\n factors = []\n for i...
code_alpaca
code_alpaca_217
[ { "role": "user", "content": "Task: Create a program to check if a given string is a palindrome\n\n\"racecar\"\n\nAnswer:" }, { "role": "assistant", "content": "\"\"\"\nCreate a program to check if a given string is a palindrome\n\"\"\"\n\ndef is_palindrome(string):\n n = len(string)\n for...
code_alpaca
code_alpaca_218
[ { "role": "user", "content": "Create a program to generate all possible pairs of a given list of numbers\n\n[1, 2, 3]\n\n" }, { "role": "assistant", "content": "\"\"\"\nCreate a program to generate all possible pairs of a given list of numbers\n\"\"\"\n\ndef generate_pairs(nums):\n pairs = []...
code_alpaca
code_alpaca_219
[ { "role": "user", "content": "Create a program that extracts a given pattern from a given string\ntext = \"Hello world!\", pattern = \"l\"\n\n" }, { "role": "assistant", "content": "\"\"\"\nCreate a program that extracts a given pattern from a given string\n\"\"\"\n\ndef extract_pattern(text, pa...
code_alpaca
code_alpaca_220
[ { "role": "user", "content": "Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a Python program to split special characters with a given string.\n\n### Input:\nstring = \"H...
code_alpaca
code_alpaca_221
[ { "role": "user", "content": "Task: Create a regex to match the characters \"CDE\" in any order.\n\n" }, { "role": "assistant", "content": "regex = r\"(C|D|E){3}\"" } ]
code_alpaca
code_alpaca_222
[ { "role": "user", "content": "Convert the following string to a list of strings.\nwords = \"How are you doing today\"\n\nResponse:" }, { "role": "assistant", "content": "words = [\"How\", \"are\", \"you\", \"doing\", \"today\"]" } ]
code_alpaca
code_alpaca_223
[ { "role": "user", "content": "You need to complete the following task:\n\nGenerate a 5x5 array with all its elements equal to 1.\n\n" }, { "role": "assistant", "content": "arr = [[1,1,1,1,1],\n [1,1,1,1,1],\n [1,1,1,1,1],\n [1,1,1,1,1],\n [1,1,1,1,1]]" } ]
code_alpaca
code_alpaca_224
[ { "role": "user", "content": "Given a list of numbers, find the index of the greatest value.\n\nlst = [3, 5, 6, 8, 9]\n\n" }, { "role": "assistant", "content": "index = 4" } ]
code_alpaca
code_alpaca_225
[ { "role": "user", "content": "Classify the following sentence as positive or negative sentiment.\n\nAdditional Context:\nThis is the worst experience ever.\n\nAnswer:" }, { "role": "assistant", "content": "Negative sentiment." } ]
code_alpaca
code_alpaca_226
[ { "role": "user", "content": "Create a web page with a centered title and paragraph in HTML.\ntitle = \"My First Web Page\"\nparagraph = \"This is my first web page. It is an amazing experience!\"\n\nResponse:" }, { "role": "assistant", "content": "<!DOCTYPE html>\n<html>\n <head>\n <t...
code_alpaca
code_alpaca_227
[ { "role": "user", "content": "Instruction:Create a JavaScript function that finds the shortest word in a string.\n\nInput: sentence = \"I'm so excited to begin this journey\"\n\n" }, { "role": "assistant", "content": "function findShortestWord(sentence) { \n let words = sentence.split(\" \");...
code_alpaca
code_alpaca_228
[ { "role": "user", "content": "Find the total number of elements in the following array.\n\nmy_array = [[1,2], 3, 4]\n\n" }, { "role": "assistant", "content": "Total number of elements = 4" } ]
code_alpaca
code_alpaca_229
[ { "role": "user", "content": "Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a SQL query to find the names of customers who have ordered products.\n\n### Response:" }, { "role": "assistant", "content": "SELECT c.name\nFROM customers c, orders o\nWHERE o.cus...
code_alpaca
code_alpaca_230
[ { "role": "user", "content": "Classify the following sentence as a question or a statement.\n\nHave you ever tried eating a brussel sprout?\n\n" }, { "role": "assistant", "content": "Question." } ]
code_alpaca
code_alpaca_231
[ { "role": "user", "content": "Write a Python program that tests if a given number is divisible by 3.\n\nnum = 51\n\n" }, { "role": "assistant", "content": "if (num % 3 == 0):\n print(\"The number is divisible by 3\")\nelse:\n print(\"The number is not divisible by 3\")" } ]
code_alpaca
code_alpaca_232
[ { "role": "user", "content": "Edit the following code so it outputs the odd numbers between 1 and 50.\n\nAdditional Context:\nfor i in range(1,51):\n print(i)\n\nAnswer:" }, { "role": "assistant", "content": "for i in range(1,51):\n if i % 2 != 0:\n print(i)" } ]
code_alpaca
code_alpaca_233
[ { "role": "user", "content": "Task: Write a function to compare two strings and return True if they are anagrams.\n\nstr1 = 'silent'\nstr2 = 'listen'\n\n" }, { "role": "assistant", "content": "def anagram(str1, str2): \n\n # Get lenghts of both strings \n n1 = len(str1) \n n2 = len(str2...
code_alpaca
code_alpaca_234
[ { "role": "user", "content": "Write a function that takes a list of integers as inputs and returns the sum of the square of all the even numbers.\nlst = [2, 8, 9, 5, 3, 10]\n\n" }, { "role": "assistant", "content": "def sum_square_even(lst):\n result = 0\n for num in lst:\n if (num ...
code_alpaca
code_alpaca_235
[ { "role": "user", "content": "Using the input string, write a code to replace the \"!\" with a \"?\".\n\nstring = \"Hello World!\"\n\n" }, { "role": "assistant", "content": "string = \"Hello World!\"\nstring = string.replace(\"!\", \"?\")\nprint(string)" } ]
code_alpaca
code_alpaca_236
[ { "role": "user", "content": "Instruction:Write a code to take two string inputs and generate the output string containing alternate characters from each string.\n\nInput: str1 = 'abc'\nstr2 = '123'\n\n" }, { "role": "assistant", "content": "def alternate_char(str1, str2):\n # get the length ...
code_alpaca
code_alpaca_237
[ { "role": "user", "content": "Given a list of strings, write a code to find the longest string.\nlst = ['one', 'two', 'three', 'four', 'five']\n\n" }, { "role": "assistant", "content": "# initial max length\nmax_length = 0\n# empty string to store the max length string\nmax_str = ''\n\n# iterate...
code_alpaca
code_alpaca_238
[ { "role": "user", "content": "Task: Write a SQL query to get the total amount from orders table where status is \"complete\".\n\n" }, { "role": "assistant", "content": "SELECT SUM(amount)\nFROM orders\nWHERE status = 'completed';" } ]
code_alpaca
code_alpaca_239
[ { "role": "user", "content": "Task: Write a function to get the mean of the given list of numbers.\nInput: lst = [1, 4, 5, 9, 3]\nOutput:" }, { "role": "assistant", "content": "def mean(lst):\n # calculate the sum\n total = 0\n for item in lst:\n total += item\n \n # calcul...
code_alpaca
code_alpaca_240
[ { "role": "user", "content": "Write a Django Model API to store status and published date for a blog post. Output:" }, { "role": "assistant", "content": "from django.db import models\n\nclass BlogPost(models.Model):\n # post title\n title = models.CharField(max_length = 200)\n # post st...
code_alpaca
code_alpaca_241
[ { "role": "user", "content": "Write a code to compare two lists and find the common elements.\n\nAdditional Context:\nlist1 = [3, 6, 9, 12]\nlist2 = [2, 4, 5, 6, 8, 9]\n\nAnswer:" }, { "role": "assistant", "content": "def find_common(list1, list2):\n # initial list to store common elements\n ...
code_alpaca
code_alpaca_242
[ { "role": "user", "content": "Write an algorithm to check if an array contains a given value\narr = [1, 7, 5, 8, 44]\nvalue = 5\n\nResponse:" }, { "role": "assistant", "content": "def check_value(arr, value):\n for item in arr:\n if item == value:\n return True\n return F...
code_alpaca
code_alpaca_243
[ { "role": "user", "content": "Write a response that appropriately completes the request.\n\n### Instruction:\nWrite a Java program to print out the first n prime numbers\n\n### Response:" }, { "role": "assistant", "content": "public static void printPrimeNumbers(int n) \n { \n int num;...
code_alpaca
code_alpaca_244
[ { "role": "user", "content": "Write a SQL query to find the names of all employees working at a given department\n" }, { "role": "assistant", "content": "SELECT e.name \nFROM employee e \nJOIN department d ON e.departmentid = d.id \nWHERE d.name = 'given department'" } ]
code_alpaca
code_alpaca_245
[ { "role": "user", "content": "You need to complete the following task:\n\nWrite a function to determine if two strings are anagrams of each other\n\n" }, { "role": "assistant", "content": "def are_anagrams(str1, str2):\n if len(str1) != len(str2):\n return False\n\n freq1 = {}\n ...
code_alpaca
code_alpaca_246
[ { "role": "user", "content": "Write a JavaScript code to calculate the factorial of a number\n" }, { "role": "assistant", "content": "function factorial(n){\n if (n == 0){\n return 1;\n }\n else{\n return n * factorial(n - 1);\n }\n}" } ]
code_alpaca
code_alpaca_247
[ { "role": "user", "content": "Write C++ code to find the maximum subarray sum" }, { "role": "assistant", "content": "\nint maxSubarraySum(int arr[], int n) { \n int max_so_far = 0, max_ending_here = 0; \n \n for (int i = 0; i < n; i++) { \n max_ending_here = max_ending_here + arr[i...
code_alpaca
code_alpaca_248
[ { "role": "user", "content": "Instruction: Write an algorithm to generate the Fibonacci series up to the nth term\nOutput:" }, { "role": "assistant", "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...
code_alpaca
code_alpaca_249
[ { "role": "user", "content": "Connect to a MySQL database and select all rows from Customers where Phone is greater than 1000.\n" }, { "role": "assistant", "content": "import mysql.connector\n\nmydb = mysql.connector.connect(\n host=\"localhost\",\n user=\"\",\n passwd=\"\",\n database=\"myd...
code_alpaca
code_alpaca_250
[ { "role": "user", "content": "Write a function that checks if a string is a palindrome or not.\nstring = \"ana\"\n" }, { "role": "assistant", "content": "def is_palindrome(string):\n rev = ''.join(reversed(string))\n if rev == string:\n return True\n else:\n return False" ...
code_alpaca
code_alpaca_251
[ { "role": "user", "content": "You need to complete the following task:\n\nChange the following array so that it orders in ascending order\n\narray = [3, 7, 1, 8, 4]\n\nAnswer:" }, { "role": "assistant", "content": "array.sort()" } ]
code_alpaca
code_alpaca_252
[ { "role": "user", "content": "Read a code and identify the data type of the variables a and b\n\na = 8\nb = \"Hello\"\n\n" }, { "role": "assistant", "content": "A is an integer and B is a string." } ]
code_alpaca
code_alpaca_253
[ { "role": "user", "content": "Write a simple calculator program.\nResponse:" }, { "role": "assistant", "content": "def calculator():\n number1 = int(input(\"Please enter first number: \"))\n number2 = int(input(\"Please enter second number: \"))\n print(\"Please choose operation -\\n\" ...
code_alpaca
code_alpaca_254
[ { "role": "user", "content": "Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nParse the string \"Hello[1]World[4]123[3]\" into a list.\n\n### Input:\nstring = \"Hello[1]World[4]...
code_alpaca
code_alpaca_255
[ { "role": "user", "content": "Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nRead the following two JSON strings and merge them\n\n### Input:\njson1 = {\n \"name\": \"John\"...
code_alpaca
code_alpaca_256
[ { "role": "user", "content": "Write a code to return the first 3 elements in a list.\n\nmylist = [1,4,3,6,7,2,4]\n\n" }, { "role": "assistant", "content": "mylist[:3]" } ]
code_alpaca
code_alpaca_257
[ { "role": "user", "content": "Change the following array so that it only contains numbers divisible by 3\nmylist = [2, 4, 5, 6, 7, 11, 12, 22]\n\n" }, { "role": "assistant", "content": "mylist = [x for x in mylist if x % 3 == 0]" } ]
code_alpaca
code_alpaca_258
[ { "role": "user", "content": "Write a function to remove duplicate items in a list.\nmylist = [2, 3, 3, 4, 5, 6, 4, 7]\n\n" }, { "role": "assistant", "content": "def remove_duplicates(mylist):\n return set(mylist)" } ]
code_alpaca
code_alpaca_259
[ { "role": "user", "content": "Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nRead a code and find all the function calls that are made.\n\n### Input:\nprint('Hello world!')\nmy...
code_alpaca
code_alpaca_260
[ { "role": "user", "content": "Instruction:Write a code to delete all items from a list with a value of 3.\n\nInput: mylist = [2, 3, 3, 4, 5, 6, 4, 7]\n\n" }, { "role": "assistant", "content": "mylist = [item for item in mylist if item != 3]" } ]
code_alpaca
code_alpaca_261
[ { "role": "user", "content": "Tell me how would you respond to the following request.\nConnect to a MongoDB database and select all documents from the collection ‘customers’.\n" }, { "role": "assistant", "content": "import pymongo\n\nmyclient = pymongo.MongoClient(\"mongodb://localhost:27017/\")...
code_alpaca
code_alpaca_262
[ { "role": "user", "content": "Create a new array that contains only the even numbers from a given array.\narr = [1, 2, 3, 4, 5, 6, 7, 8]\n" }, { "role": "assistant", "content": "arr = [x for x in arr if x % 2 == 0]" } ]
code_alpaca
code_alpaca_263
[ { "role": "user", "content": "Find the number of times a letter appears in a string.\n\nstring = \"Hello World\"\nletter = 'l'\n\n" }, { "role": "assistant", "content": "count = string.count(letter)" } ]
code_alpaca
code_alpaca_264
[ { "role": "user", "content": "Plase answer the following request: Create a for loop to print the numbers from 1 to 100.\nAnswer:" }, { "role": "assistant", "content": "for i in range(1, 101):\n print(i)" } ]
code_alpaca
code_alpaca_265
[ { "role": "user", "content": "Task: Estimate the time complexity of the following algorithm.\n\nfor i in range(n):\n for j in range(n):\n print(i + j)\n\nAnswer:" }, { "role": "assistant", "content": "O(n^2)" } ]
code_alpaca
code_alpaca_266
[ { "role": "user", "content": "Task: Write a code snippet to return the item with the highest value in a given dictionary.\nInput: d = {'a':20, 'b':10, 'c':15}\nOutput:" }, { "role": "assistant", "content": "key = max(d, key = d.get) \nval = d[key]\nreturn (key, val)" } ]
code_alpaca
code_alpaca_267
[ { "role": "user", "content": "Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nFor the following two arrays, create a code snippet to return the intersecting element.\n\n### Inpu...
code_alpaca
code_alpaca_268
[ { "role": "user", "content": "Instruction: Using the numpy library, create a 3x3 Identity Matrix.\nOutput:" }, { "role": "assistant", "content": "iden_matrix = numpy.identity(3) \nprint(iden_matrix)" } ]
code_alpaca
code_alpaca_269
[ { "role": "user", "content": "Create a Linked List Node with the data of type integer.\n\n" }, { "role": "assistant", "content": "class Node: \n \n # Function to initializaee the node object \n def __init__(self, data): \n self.data = data # Assign data \n self.next = None # Initialize ...
code_alpaca
code_alpaca_270
[ { "role": "user", "content": "Plase answer the following request: Generate a unique and random password for a user using python.\nAnswer:" }, { "role": "assistant", "content": "import random \ncharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+-=[ ]{}:'\npass...
code_alpaca
code_alpaca_271
[ { "role": "user", "content": "Given a binary tree, write a code snippet to list all of its descendant leafs.\n" }, { "role": "assistant", "content": "def listDescendantLeaves(root):\n if not root: \n return\n elif not root.left and not root.right: \n print(root.val) \n lis...
code_alpaca
code_alpaca_272
[ { "role": "user", "content": "Task: Given a string, write a function to remove all the duplicate characters.\n\nstring = \"apple\"\n\n" }, { "role": "assistant", "content": "def remove_duplicates(string): \n new_string = \"\" \n for char in string:\n if char not in new_string:\n ...
code_alpaca
code_alpaca_273
[ { "role": "user", "content": "Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nclassify the following sentence using a sentiment analysis model.\n\n### Input:\nThe movie is aweso...
code_alpaca
code_alpaca_274
[ { "role": "user", "content": "convert all words in a sentence to camelCase\n\nThe quick brown fox jumps over the lazy dog\n\n" }, { "role": "assistant", "content": "\"\"\"\nConvert all words in a sentence to camelCase\n\nInput: The quick brown fox jumps over the lazy dog\n\nOutput: theQuickBrown...
code_alpaca
code_alpaca_275
[ { "role": "user", "content": "Write a function to calculate the average score of a list of numbers.\n\n" }, { "role": "assistant", "content": "def get_average(numbers):\n \"\"\"\n Calculate and return the average of a list of numbers\n :param numbers: the list of numbers\n :return: t...
code_alpaca
code_alpaca_276
[ { "role": "user", "content": "Write a function to find the longest string in a list of strings.\n\n" }, { "role": "assistant", "content": "def find_longest_string(strings):\n \"\"\"\n Find and return the longest string in a list of strings.\n :param strings: the list of strings\n :re...
code_alpaca
code_alpaca_277
[ { "role": "user", "content": "Task: Implement a function to extract the last two words from a string of words\n\n" }, { "role": "assistant", "content": "def get_last_two_words(string):\n \"\"\"\n Extract and return the last two words from a string of words\n :param string: the input str...
code_alpaca
code_alpaca_278
[ { "role": "user", "content": "Write code to find the intersection of two sorted lists\nlist1 = [1, 3, 4, 6]\nlist2 = [1, 2, 5, 6]\n\n" }, { "role": "assistant", "content": "def find_intersection(list1, list2):\n \"\"\"\n Find the intersection of two sorted lists\n :param list1: the firs...
code_alpaca
code_alpaca_279
[ { "role": "user", "content": "Instruction: Write code to flatten a nested list\n" }, { "role": "assistant", "content": "def flatten_list(list):\n \"\"\"\n Flatten a nested list\n :param list: the nested list to flatten\n :return: a flattened list\n \"\"\"\n flattened_list = []\...
code_alpaca
code_alpaca_280
[ { "role": "user", "content": "You need to complete the following task:\n\nWrite code to remove all occurrences of a given element from a list\n\n" }, { "role": "assistant", "content": "def remove_element(list, element):\n \"\"\"\n Remove all occurrences of a given element from a list\n ...
code_alpaca
code_alpaca_281
[ { "role": "user", "content": "Generate pseudocode for a matrix multiplication algorithm.\n" }, { "role": "assistant", "content": "\"\"\"\nGenerate pseudocode for a matrix multiplication algorithm.\n\"\"\"\n\n# Create an NxN matrix result, initialized to 0\nresult = zeros(NxN)\n\n# loop through m...
code_alpaca
code_alpaca_282
[ { "role": "user", "content": "Instruction: Create a function to generate a random password of length n\n" }, { "role": "assistant", "content": "import random\n\ndef generate_password(n):\n \"\"\"\n Create a function to generate a random password of length n\n :param n: the length of the...
code_alpaca
code_alpaca_283
[ { "role": "user", "content": "Debug the following Python code\ndef f(x):\n if x > 0:\n return -1\n else:\n return 1\n\n" }, { "role": "assistant", "content": "\"\"\"\nDebug the following Python code\n\ndef f(x):\n if x > 0:\n return -1\n else:\n return 1\n...
code_alpaca
code_alpaca_284
[ { "role": "user", "content": "Generate a data structure that can efficiently store an array of words\nResponse:" }, { "role": "assistant", "content": "\"\"\"\nGenerate a data structure that can efficiently store an array of words\n\"\"\"\n\n# create a trie (a node with 26 references to other nod...
code_alpaca
code_alpaca_285
[ { "role": "user", "content": "Write a response that appropriately completes the request.\n\n### Instruction:\nCreate a function to find the position of a substring in a string\n\n### Response:" }, { "role": "assistant", "content": "def find_substring(string, substring):\n \"\"\"\n Find the...
code_alpaca
code_alpaca_286
[ { "role": "user", "content": "Plase answer the following request: Reorder a given array in specialized order\nAnswer:" }, { "role": "assistant", "content": "def reorder_array(arr):\n \"\"\"\n Reorder a given array in specialized order\n :param arr: the input array to reorder\n :retur...
code_alpaca
code_alpaca_287
[ { "role": "user", "content": "Write an HTML code to create a horizontal line.\n\n" }, { "role": "assistant", "content": "<hr>" } ]
code_alpaca
code_alpaca_288
[ { "role": "user", "content": "Design a function in Python that returns the median of an array of integers. Output:" }, { "role": "assistant", "content": "def median(arr):\n sortedArr = sorted(arr)\n length = len(arr)\n if length % 2 == 0:\n return ((sortedArr[length//2-1] + sortedArr[lengt...
code_alpaca
code_alpaca_289
[ { "role": "user", "content": "Write a JavaScript code to valid a password based on the following rules:\n" }, { "role": "assistant", "content": "function validatePassword(password) {\n // Minimum 8 characters, one uppercase letter, one lowercase letter, one number, and one special character\n ...
code_alpaca
code_alpaca_290
[ { "role": "user", "content": "Write a code to reverse the order of a data structure such as array, list, or stack.\n\nlist1 = [1, 3, 5, 7, 9]\n\n" }, { "role": "assistant", "content": "list1.reverse() # [9, 7, 5, 3, 1]" } ]
code_alpaca
code_alpaca_291
[ { "role": "user", "content": "You need to complete the following task:\n\nCreate a program in C++ that calculates the absolute difference between two numbers.\n\nnum1 = 50;\nnum2 = 40;\n\nAnswer:" }, { "role": "assistant", "content": "#include <iostream>\nusing namespace std;\n\nint main() \n{\n...
code_alpaca
code_alpaca_292
[ { "role": "user", "content": "Instruction: Design an HTML form with the following fields: first name, last name, age, phone number and address.\n" }, { "role": "assistant", "content": "<form> \n <label> First Name: </label> \n <input type=\"text\" name=\"firstname\" required> \n <label> Last ...
code_alpaca
code_alpaca_293
[ { "role": "user", "content": "Create a Ruby program to check if a number is even or odd.\n" }, { "role": "assistant", "content": "def is_even(number)\n number % 2 == 0\nend" } ]
code_alpaca
code_alpaca_294
[ { "role": "user", "content": "Task: Redesign the following Python program with functions.\n\nmy_list = [5, 10, 15, 20]\nsum = 0\nfor number in my_list:\nsum = sum + number\n\nAnswer:" }, { "role": "assistant", "content": "def sum_of_list(my_list):\n sum = 0\n for number in my_list:\n sum = ...
code_alpaca
code_alpaca_295
[ { "role": "user", "content": "Task: Create an HTML page displaying a table of 3 rows and 3 columns.\n\n" }, { "role": "assistant", "content": "<table>\n <tr>\n <td>Column 1</td>\n <td>Column 2</td>\n <td>Column 3</td>\n </tr>\n <tr>\n <td>Row 1</td>\n <td>Row 1</td>\n <td>Ro...
code_alpaca
code_alpaca_296
[ { "role": "user", "content": "Debug the following JavaScript code which calculates the average of an array of integers:\n\nInput: arr = [2, 3, 4, 5]\nsum = 0\nfor (i = 0; i < arr.length; i++) {\nsum += arr[i]}\naverage = sum / arr.length\n\nOutput:" }, { "role": "assistant", "content": "arr = [2...
code_alpaca
code_alpaca_297
[ { "role": "user", "content": "Generate an random integer between 1 and 6.\n\n" }, { "role": "assistant", "content": "Math.floor(Math.random() * 6) + 1;" } ]
code_alpaca
code_alpaca_298
[ { "role": "user", "content": "Create a program that prints the first 10 Fibonacci numbers.\n\n" }, { "role": "assistant", "content": "\"\"\"\nPrint the first ten Fibonacci numbers\n\"\"\"\n\ndef print_first_ten_fibonacci_numbers():\n \"\"\"Print the first ten Fibonacci numbers.\"\"\"\n\n n...
code_alpaca
code_alpaca_299
[ { "role": "user", "content": "Instruction:Calculate the sum of an array of integers\n\nInput: [3, 5, 7, 9]\n\n" }, { "role": "assistant", "content": "24" } ]