messages listlengths 2 2 | conversation_id int64 0 20k |
|---|---|
[
{
"content": "Write a code to check whether two strings are anagrams or not.\nfirst = \"listen\"\nsecond = \"silent\"",
"role": "user"
},
{
"content": "\"\"\"\nWrite a code to check whether two strings are anagrams or not\n\"\"\"\n\n# Strings to be checked\nfirst = \"listen\"\nsecond = \"silent\"\n\... | 200 |
[
{
"content": "Write a code to delete all the vowels from a given string.\nstring = \"hello world\"",
"role": "user"
},
{
"content": "\"\"\"\nWrite a code to delete all the vowels from a given string\n\"\"\"\n\n# Given string\nstring = \"hello world\"\n\n# Removing all the vowels from the string\nno_... | 201 |
[
{
"content": "Write a code to convert a given list of strings to uppercase.\nmylist = [\"hello\",\"world\"]",
"role": "user"
},
{
"content": "\"\"\"\nWrite a code to convert a given list of strings to uppercase\n\"\"\"\n\n# List containing the strings\nmylist = [\"hello\",\"world\"]\n\n# Converting ... | 202 |
[
{
"content": "Write a code to find the maximum in a given list of integers.\nmylist = [1,2,3,4,5]",
"role": "user"
},
{
"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# Finding the maximum element\nm... | 203 |
[
{
"content": "Write a code to generate the multiplication table of a given integer.\nx = 5",
"role": "user"
},
{
"content": "\"\"\"\nWrite a code to generate the multiplication table of a given integer\n\"\"\"\n\n# Number for which multiplication table will be generated\nx = 5\n\n# Generating the mu... | 204 |
[
{
"content": "Write a code to merge two given lists of equal size.\nlist1 = [1,2,3]\nlist2 = [4,5,6]",
"role": "user"
},
{
"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 an empty list\nmerged_list =... | 205 |
[
{
"content": "Write a code to compute the mean of an input list of numbers.\nmylist = [1,2,3,4,5]",
"role": "user"
},
{
"content": "\"\"\"\nWrite a code to compute the mean of an input list of numbers\n\"\"\"\n\n# List containing the elements\nmylist = [1,2,3,4,5]\n\n# Computing the sum and number o... | 206 |
[
{
"content": "Create a program to convert the input sentence to Pig Latin.\nI am a computer programmer",
"role": "user"
},
{
"content": "\"\"\"\nCreate a program to convert the input sentence to Pig Latin.\n\"\"\"\n\ndef pig_latin(sentence):\n words = sentence.split()\n new_words = []\n for... | 207 |
[
{
"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}",
"role": "user"
},
{
"content": "\"\"\"\nCreate a program to write an overwriting if-else logic for the... | 208 |
[
{
"content": "Write a function that sorts the given list of numbers in descending order\n[1, 2, 3, 5, 8, 10]",
"role": "user"
},
{
"content": "\"\"\"\nWrite a function that sorts the given list of numbers in descending order\n\"\"\"\n\ndef sort_list_descending(numbers):\n numbers.sort(reverse = T... | 209 |
[
{
"content": "Create a program to create a list of all the numbers from 1 to 10 which are divisible by 3",
"role": "user"
},
{
"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():\n divisible_by_three_l... | 210 |
[
{
"content": "rewrite the following for-loop as a while-loop\nfor i in range(0, 5):\n print(i)",
"role": "user"
},
{
"content": "\"\"\"\nRewrite the following for-loop as a while-loop\n\"\"\"\n\ni = 0\nwhile i < 5:\n print(i)\n i += 1",
"role": "assistant"
}
] | 211 |
[
{
"content": "Create a program to compute the checksum of a given data packet\ndata_packet = [0xff, 0x0a, 0x1b, 0x3f]",
"role": "user"
},
{
"content": "\"\"\"\nCreate a program to compute the checksum of a given data packet\n\"\"\"\n\ndef compute_checksum(data_packet):\n checksum = 0\n for x i... | 212 |
[
{
"content": "Create a program to parse a given string and return a dictionary with all the words and their frequency\n\"this is a practice string to learn the parsing of strings\"",
"role": "user"
},
{
"content": "\"\"\"\nCreate a program to parse a given string and return a dictionary with all the... | 213 |
[
{
"content": "Create a program to classify whether the given number is even or odd\n5",
"role": "user"
},
{
"content": "\"\"\"\nCreate a program to classify whether the given number is even or odd\n\"\"\"\n\ndef even_or_odd(number: int) -> str:\n if number % 2 == 0:\n return 'even'\n el... | 214 |
[
{
"content": "Create a program to generate the sum of all the elements in a given list\n[1, 2, 3, 4, 5]",
"role": "user"
},
{
"content": "\"\"\"\nCreate a program to generate the sum of all the elements in a given list\n\"\"\"\n\ndef sum_list(nums):\n total = 0\n for num in nums:\n tota... | 215 |
[
{
"content": "Create a program to find all the factors of a given number\n24",
"role": "user"
},
{
"content": "\"\"\"\nCreate a program to find all the factors of a given number \n\"\"\"\n\ndef find_factors(num):\n factors = []\n for i in range(1, num+1):\n if num % i == 0:\n ... | 216 |
[
{
"content": "Create a program to check if a given string is a palindrome\n\"racecar\"",
"role": "user"
},
{
"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 i in range(n // 2):\n if string[i] !... | 217 |
[
{
"content": "Create a program to generate all possible pairs of a given list of numbers\n[1, 2, 3]",
"role": "user"
},
{
"content": "\"\"\"\nCreate a program to generate all possible pairs of a given list of numbers\n\"\"\"\n\ndef generate_pairs(nums):\n pairs = []\n for i in range(len(nums))... | 218 |
[
{
"content": "Create a program that extracts a given pattern from a given string\ntext = \"Hello world!\", pattern = \"l\"",
"role": "user"
},
{
"content": "\"\"\"\nCreate a program that extracts a given pattern from a given string\n\"\"\"\n\ndef extract_pattern(text, pattern):\n result = []\n ... | 219 |
[
{
"content": "Write a Python program to split special characters with a given string.\nstring = \"Hello@#World\"",
"role": "user"
},
{
"content": "string = \"Hello @# World\"",
"role": "assistant"
}
] | 220 |
[
{
"content": "Create a regex to match the characters \"CDE\" in any order.",
"role": "user"
},
{
"content": "regex = r\"(C|D|E){3}\"",
"role": "assistant"
}
] | 221 |
[
{
"content": "Convert the following string to a list of strings.\nwords = \"How are you doing today\"",
"role": "user"
},
{
"content": "words = [\"How\", \"are\", \"you\", \"doing\", \"today\"]",
"role": "assistant"
}
] | 222 |
[
{
"content": "Generate a 5x5 array with all its elements equal to 1.",
"role": "user"
},
{
"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]]",
"role": "assistant"
}
] | 223 |
[
{
"content": "Given a list of numbers, find the index of the greatest value.\nlst = [3, 5, 6, 8, 9]",
"role": "user"
},
{
"content": "index = 4",
"role": "assistant"
}
] | 224 |
[
{
"content": "Classify the following sentence as positive or negative sentiment.\nThis is the worst experience ever.",
"role": "user"
},
{
"content": "Negative sentiment.",
"role": "assistant"
}
] | 225 |
[
{
"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!\"",
"role": "user"
},
{
"content": "<!DOCTYPE html>\n<html>\n <head>\n <title>My First Web Page</title>\n </... | 226 |
[
{
"content": "Create a JavaScript function that finds the shortest word in a string.\nsentence = \"I'm so excited to begin this journey\"",
"role": "user"
},
{
"content": "function findShortestWord(sentence) { \n let words = sentence.split(\" \"); \n let shortestWord = words[0]; \n \n for ... | 227 |
[
{
"content": "Find the total number of elements in the following array.\nmy_array = [[1,2], 3, 4]",
"role": "user"
},
{
"content": "Total number of elements = 4",
"role": "assistant"
}
] | 228 |
[
{
"content": "Write a SQL query to find the names of customers who have ordered products.",
"role": "user"
},
{
"content": "SELECT c.name\nFROM customers c, orders o\nWHERE o.customer_id = c.id",
"role": "assistant"
}
] | 229 |
[
{
"content": "Classify the following sentence as a question or a statement.\nHave you ever tried eating a brussel sprout?",
"role": "user"
},
{
"content": "Question.",
"role": "assistant"
}
] | 230 |
[
{
"content": "Write a Python program that tests if a given number is divisible by 3.\nnum = 51",
"role": "user"
},
{
"content": "if (num % 3 == 0):\n print(\"The number is divisible by 3\")\nelse:\n print(\"The number is not divisible by 3\")",
"role": "assistant"
}
] | 231 |
[
{
"content": "Edit the following code so it outputs the odd numbers between 1 and 50.\nfor i in range(1,51):\n print(i)",
"role": "user"
},
{
"content": "for i in range(1,51):\n if i % 2 != 0:\n print(i)",
"role": "assistant"
}
] | 232 |
[
{
"content": "Write a function to compare two strings and return True if they are anagrams.\nstr1 = 'silent'\nstr2 = 'listen'",
"role": "user"
},
{
"content": "def anagram(str1, str2): \n\n # Get lenghts of both strings \n n1 = len(str1) \n n2 = len(str2) \n \n # If lengths are not same... | 233 |
[
{
"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]",
"role": "user"
},
{
"content": "def sum_square_even(lst):\n result = 0\n for num in lst:\n if (num % 2 == 0):\n resul... | 234 |
[
{
"content": "Using the input string, write a code to replace the \"!\" with a \"?\".\nstring = \"Hello World!\"",
"role": "user"
},
{
"content": "string = \"Hello World!\"\nstring = string.replace(\"!\", \"?\")\nprint(string)",
"role": "assistant"
}
] | 235 |
[
{
"content": "Write a code to take two string inputs and generate the output string containing alternate characters from each string.\nstr1 = 'abc'\nstr2 = '123'",
"role": "user"
},
{
"content": "def alternate_char(str1, str2):\n # get the length of string\n n = len(str1)\n\n # initialize t... | 236 |
[
{
"content": "Given a list of strings, write a code to find the longest string.\nlst = ['one', 'two', 'three', 'four', 'five']",
"role": "user"
},
{
"content": "# initial max length\nmax_length = 0\n# empty string to store the max length string\nmax_str = ''\n\n# iterate through the list\nfor string... | 237 |
[
{
"content": "Write a SQL query to get the total amount from orders table where status is \"complete\".",
"role": "user"
},
{
"content": "SELECT SUM(amount)\nFROM orders\nWHERE status = 'completed';",
"role": "assistant"
}
] | 238 |
[
{
"content": "Write a function to get the mean of the given list of numbers.\nlst = [1, 4, 5, 9, 3]",
"role": "user"
},
{
"content": "def mean(lst):\n # calculate the sum\n total = 0\n for item in lst:\n total += item\n \n # calculate the mean\n mean = total / len(lst)\n ... | 239 |
[
{
"content": "Write a Django Model API to store status and published date for a blog post.",
"role": "user"
},
{
"content": "from django.db import models\n\nclass BlogPost(models.Model):\n # post title\n title = models.CharField(max_length = 200)\n # post status (draft / published)\n sta... | 240 |
[
{
"content": "Write a code to compare two lists and find the common elements.\nlist1 = [3, 6, 9, 12]\nlist2 = [2, 4, 5, 6, 8, 9]",
"role": "user"
},
{
"content": "def find_common(list1, list2):\n # initial list to store common elements\n result = []\n\n # iterate through the list\n for n... | 241 |
[
{
"content": "Write an algorithm to check if an array contains a given value\narr = [1, 7, 5, 8, 44]\nvalue = 5",
"role": "user"
},
{
"content": "def check_value(arr, value):\n for item in arr:\n if item == value:\n return True\n return False",
"role": "assistant"
}
] | 242 |
[
{
"content": "Write a Java program to print out the first n prime numbers",
"role": "user"
},
{
"content": "public static void printPrimeNumbers(int n) \n { \n int num; \n int count=0;\n for (int i = 2; i <= n;) \n { \n num=0; \n for (int j = 2; j... | 243 |
[
{
"content": "Write a SQL query to find the names of all employees working at a given department",
"role": "user"
},
{
"content": "SELECT e.name \nFROM employee e \nJOIN department d ON e.departmentid = d.id \nWHERE d.name = 'given department'",
"role": "assistant"
}
] | 244 |
[
{
"content": "Write a function to determine if two strings are anagrams of each other",
"role": "user"
},
{
"content": "def are_anagrams(str1, str2):\n if len(str1) != len(str2):\n return False\n\n freq1 = {}\n freq2 = {}\n\n for char in str1:\n if char not in freq1:\n ... | 245 |
[
{
"content": "Write a JavaScript code to calculate the factorial of a number",
"role": "user"
},
{
"content": "function factorial(n){\n if (n == 0){\n return 1;\n }\n else{\n return n * factorial(n - 1);\n }\n}",
"role": "assistant"
}
] | 246 |
[
{
"content": "Write C++ code to find the maximum subarray sum",
"role": "user"
},
{
"content": "int 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]; \n if (max_so_far... | 247 |
[
{
"content": "Write an algorithm to generate the Fibonacci series up to the nth term",
"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 else:... | 248 |
[
{
"content": "Connect to a MySQL database and select all rows from Customers where Phone is greater than 1000.",
"role": "user"
},
{
"content": "import mysql.connector\n\nmydb = mysql.connector.connect(\n host=\"localhost\",\n user=\"\",\n passwd=\"\",\n database=\"mydatabase\"\n)\n\nmycursor = ... | 249 |
[
{
"content": "Write a function that checks if a string is a palindrome or not.\nstring = \"ana\"",
"role": "user"
},
{
"content": "def is_palindrome(string):\n rev = ''.join(reversed(string))\n if rev == string:\n return True\n else:\n return False",
"role": "assistant"
... | 250 |
[
{
"content": "Change the following array so that it orders in ascending order\narray = [3, 7, 1, 8, 4]",
"role": "user"
},
{
"content": "array.sort()",
"role": "assistant"
}
] | 251 |
[
{
"content": "Read a code and identify the data type of the variables a and b\na = 8\nb = \"Hello\"",
"role": "user"
},
{
"content": "A is an integer and B is a string.",
"role": "assistant"
}
] | 252 |
[
{
"content": "Write a simple calculator program.",
"role": "user"
},
{
"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\" \\\n \"1. Add\\n\" \\\n ... | 253 |
[
{
"content": "Parse the string \"Hello[1]World[4]123[3]\" into a list.\nstring = \"Hello[1]World[4]123[3]\"",
"role": "user"
},
{
"content": "my_list = string.split('[')\nmy_list = [item.replace(']', '') for item in my_list]\nmy_list = [int(item) for item in my_list[1::2]]",
"role": "assistant"
... | 254 |
[
{
"content": "Read the following two JSON strings and merge them\njson1 = {\n \"name\": \"John\",\n \"age\": 20\n}\n\njson2 = {\n \"address\": \"123 Street\"\n}",
"role": "user"
},
{
"content": "import json\n\njson1 = json.loads(json1)\njson2 = json.loads(json2)\nmerged_json = {**json1, **j... | 255 |
[
{
"content": "Write a code to return the first 3 elements in a list.\nmylist = [1,4,3,6,7,2,4]",
"role": "user"
},
{
"content": "mylist[:3]",
"role": "assistant"
}
] | 256 |
[
{
"content": "Change the following array so that it only contains numbers divisible by 3\nmylist = [2, 4, 5, 6, 7, 11, 12, 22]",
"role": "user"
},
{
"content": "mylist = [x for x in mylist if x % 3 == 0]",
"role": "assistant"
}
] | 257 |
[
{
"content": "Write a function to remove duplicate items in a list.\nmylist = [2, 3, 3, 4, 5, 6, 4, 7]",
"role": "user"
},
{
"content": "def remove_duplicates(mylist):\n return set(mylist)",
"role": "assistant"
}
] | 258 |
[
{
"content": "Read a code and find all the function calls that are made.\nprint('Hello world!')\nmy_function()\nmy_function2(2, 3)",
"role": "user"
},
{
"content": "The two function calls made are \"my_function()\" and \"my_function2(2, 3)\".",
"role": "assistant"
}
] | 259 |
[
{
"content": "Write a code to delete all items from a list with a value of 3.\nmylist = [2, 3, 3, 4, 5, 6, 4, 7]",
"role": "user"
},
{
"content": "mylist = [item for item in mylist if item != 3]",
"role": "assistant"
}
] | 260 |
[
{
"content": "Connect to a MongoDB database and select all documents from the collection ‘customers’.",
"role": "user"
},
{
"content": "import pymongo\n\nmyclient = pymongo.MongoClient(\"mongodb://localhost:27017/\")\nmydb = myclient[\"mydatabase\"]\nmycol = mydb[\"customers\"]\n\nmydoc = mycol.find... | 261 |
[
{
"content": "Create a new array that contains only the even numbers from a given array.\narr = [1, 2, 3, 4, 5, 6, 7, 8]",
"role": "user"
},
{
"content": "arr = [x for x in arr if x % 2 == 0]",
"role": "assistant"
}
] | 262 |
[
{
"content": "Find the number of times a letter appears in a string.\nstring = \"Hello World\"\nletter = 'l'",
"role": "user"
},
{
"content": "count = string.count(letter)",
"role": "assistant"
}
] | 263 |
[
{
"content": "Create a for loop to print the numbers from 1 to 100.",
"role": "user"
},
{
"content": "for i in range(1, 101):\n print(i)",
"role": "assistant"
}
] | 264 |
[
{
"content": "Estimate the time complexity of the following algorithm.\nfor i in range(n):\n for j in range(n):\n print(i + j)",
"role": "user"
},
{
"content": "O(n^2)",
"role": "assistant"
}
] | 265 |
[
{
"content": "Write a code snippet to return the item with the highest value in a given dictionary.\nd = {'a':20, 'b':10, 'c':15}",
"role": "user"
},
{
"content": "key = max(d, key = d.get) \nval = d[key]\nreturn (key, val)",
"role": "assistant"
}
] | 266 |
[
{
"content": "For the following two arrays, create a code snippet to return the intersecting element.\narr1 = [1, 9, 4, 10]\narr2 = [2, 4, 7, 8]",
"role": "user"
},
{
"content": "intersect_arr = [] \nfor i in arr1:\n if i in arr2:\n intersect_arr.append(i)\nreturn intersect_arr",
"role... | 267 |
[
{
"content": "Using the numpy library, create a 3x3 Identity Matrix.",
"role": "user"
},
{
"content": "iden_matrix = numpy.identity(3) \nprint(iden_matrix)",
"role": "assistant"
}
] | 268 |
[
{
"content": "Create a Linked List Node with the data of type integer.",
"role": "user"
},
{
"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 next as null",
"role": "a... | 269 |
[
{
"content": "Generate a unique and random password for a user using python.",
"role": "user"
},
{
"content": "import random \ncharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+-=[ ]{}:'\npassword = random.choices(characters, k = 16) \nprint(\"\".join(password))... | 270 |
[
{
"content": "Given a binary tree, write a code snippet to list all of its descendant leafs.",
"role": "user"
},
{
"content": "def listDescendantLeaves(root):\n if not root: \n return\n elif not root.left and not root.right: \n print(root.val) \n listDescendantLeaves(root.left... | 271 |
[
{
"content": "Given a string, write a function to remove all the duplicate characters.\nstring = \"apple\"",
"role": "user"
},
{
"content": "def remove_duplicates(string): \n new_string = \"\" \n for char in string:\n if char not in new_string:\n new_string += char \n retu... | 272 |
[
{
"content": "classify the following sentence using a sentiment analysis model.\nThe movie is awesome.",
"role": "user"
},
{
"content": "\"\"\"\nClassify the following sentence using a sentiment analysis model.\nSentence: The movie is awesome.\n\"\"\"\n\nfrom textblob import TextBlob\n\nsentence = \... | 273 |
[
{
"content": "convert all words in a sentence to camelCase\nThe quick brown fox jumps over the lazy dog",
"role": "user"
},
{
"content": "\"\"\"\nConvert all words in a sentence to camelCase\n\nInput: The quick brown fox jumps over the lazy dog\n\nOutput: theQuickBrownFoxJumpsOverTheLazyDog\n\"\"\"\... | 274 |
[
{
"content": "Write a function to calculate the average score of a list of numbers.",
"role": "user"
},
{
"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: the average of the numbers\n ... | 275 |
[
{
"content": "Write a function to find the longest string in a list of strings.",
"role": "user"
},
{
"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 :return: the longest string\n ... | 276 |
[
{
"content": "Implement a function to extract the last two words from a string of words",
"role": "user"
},
{
"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 string\n :return: the last two word... | 277 |
[
{
"content": "Write code to find the intersection of two sorted lists\nlist1 = [1, 3, 4, 6]\nlist2 = [1, 2, 5, 6]",
"role": "user"
},
{
"content": "def find_intersection(list1, list2):\n \"\"\"\n Find the intersection of two sorted lists\n :param list1: the first sorted list\n :param lis... | 278 |
[
{
"content": "Write code to flatten a nested list",
"role": "user"
},
{
"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 = []\n for item in list:\n if isins... | 279 |
[
{
"content": "Write code to remove all occurrences of a given element from a list",
"role": "user"
},
{
"content": "def remove_element(list, element):\n \"\"\"\n Remove all occurrences of a given element from a list\n :param list: the list\n :param element: the element to remove\n :re... | 280 |
[
{
"content": "Generate pseudocode for a matrix multiplication algorithm.",
"role": "user"
},
{
"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 matrix A and B\nfor i in ran... | 281 |
[
{
"content": "Create a function to generate a random password of length n",
"role": "user"
},
{
"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 password\n :return: a random passwor... | 282 |
[
{
"content": "Debug the following Python code\ndef f(x):\n if x > 0:\n return -1\n else:\n return 1",
"role": "user"
},
{
"content": "\"\"\"\nDebug the following Python code\n\ndef f(x):\n if x > 0:\n return -1\n else:\n return 1\n\"\"\"\n\n# incorrect indenta... | 283 |
[
{
"content": "Generate a data structure that can efficiently store an array of words",
"role": "user"
},
{
"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 nodes)\nclass TrieNode:\n def __init... | 284 |
[
{
"content": "Create a function to find the position of a substring in a string",
"role": "user"
},
{
"content": "def find_substring(string, substring):\n \"\"\"\n Find the position of a substring in a string\n :param string: the string\n :param substring: the substring to find\n :ret... | 285 |
[
{
"content": "Reorder a given array in specialized order",
"role": "user"
},
{
"content": "def reorder_array(arr):\n \"\"\"\n Reorder a given array in specialized order\n :param arr: the input array to reorder\n :return: the reordered array\n \"\"\"\n # determine the size of the ar... | 286 |
[
{
"content": "Write an HTML code to create a horizontal line.",
"role": "user"
},
{
"content": "<hr>",
"role": "assistant"
}
] | 287 |
[
{
"content": "Design a function in Python that returns the median of an array of integers.",
"role": "user"
},
{
"content": "def median(arr):\n sortedArr = sorted(arr)\n length = len(arr)\n if length % 2 == 0:\n return ((sortedArr[length//2-1] + sortedArr[length//2])/2)\n else:\n return so... | 288 |
[
{
"content": "Write a JavaScript code to valid a password based on the following rules:",
"role": "user"
},
{
"content": "function validatePassword(password) {\n // Minimum 8 characters, one uppercase letter, one lowercase letter, one number, and one special character\n const re = /^(?=.*[a-z])(?=... | 289 |
[
{
"content": "Write a code to reverse the order of a data structure such as array, list, or stack.\nlist1 = [1, 3, 5, 7, 9]",
"role": "user"
},
{
"content": "list1.reverse() # [9, 7, 5, 3, 1]",
"role": "assistant"
}
] | 290 |
[
{
"content": "Create a program in C++ that calculates the absolute difference between two numbers.\nnum1 = 50;\nnum2 = 40;",
"role": "user"
},
{
"content": "#include <iostream>\nusing namespace std;\n\nint main() \n{\n int num1 = 50;\n int num2 = 40;\n int absDiff = abs(num1 - num2);\n cout << \... | 291 |
[
{
"content": "Design an HTML form with the following fields: first name, last name, age, phone number and address.",
"role": "user"
},
{
"content": "<form> \n <label> First Name: </label> \n <input type=\"text\" name=\"firstname\" required> \n <label> Last Name: </label> \n <input type=\"text\" ... | 292 |
[
{
"content": "Create a Ruby program to check if a number is even or odd.",
"role": "user"
},
{
"content": "def is_even(number)\n number % 2 == 0\nend",
"role": "assistant"
}
] | 293 |
[
{
"content": "Redesign the following Python program with functions.\nmy_list = [5, 10, 15, 20]\nsum = 0\nfor number in my_list:\nsum = sum + number",
"role": "user"
},
{
"content": "def sum_of_list(my_list):\n sum = 0\n for number in my_list:\n sum = sum + number\n return sum\n\nmy_list = [5, ... | 294 |
[
{
"content": "Create an HTML page displaying a table of 3 rows and 3 columns.",
"role": "user"
},
{
"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>Row 1</td>\n </tr>\n <tr>\n <td>... | 295 |
[
{
"content": "Debug the following JavaScript code which calculates the average of an array of integers:\narr = [2, 3, 4, 5]\nsum = 0\nfor (i = 0; i < arr.length; i++) {\nsum += arr[i]}\naverage = sum / arr.length",
"role": "user"
},
{
"content": "arr = [2, 3, 4, 5]\nsum = 0\nfor (i = 0; i < arr.leng... | 296 |
[
{
"content": "Generate an random integer between 1 and 6.",
"role": "user"
},
{
"content": "Math.floor(Math.random() * 6) + 1;",
"role": "assistant"
}
] | 297 |
[
{
"content": "Create a program that prints the first 10 Fibonacci numbers.",
"role": "user"
},
{
"content": "\"\"\"\nPrint the first ten Fibonacci numbers\n\"\"\"\n\ndef print_first_ten_fibonacci_numbers():\n \"\"\"Print the first ten Fibonacci numbers.\"\"\"\n\n n1, n2 = 0, 1\n num = 0\n ... | 298 |
[
{
"content": "Calculate the sum of an array of integers\n[3, 5, 7, 9]",
"role": "user"
},
{
"content": "24",
"role": "assistant"
}
] | 299 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.