Datasets:
messages listlengths 2 2 | instruction stringlengths 14 288 | input stringlengths 0 635 | output stringlengths 1 3.91k |
|---|---|---|---|
[
{
"role": "user",
"content": "Compare two strings in C# and return a Boolean indicating whether they are anagrams.\n\nstring1 = \"listen\";\nstring2 = \"silent\""
},
{
"role": "assistant",
"content": "public static bool AreAnagrams(string string1, string string2)\n{\n if (String.Concat(string... | Compare two strings in C# and return a Boolean indicating whether they are anagrams. | string1 = "listen";
string2 = "silent" | public static bool AreAnagrams(string string1, string string2)
{
if (String.Concat(string1.OrderBy(c => c)) ==
String.Concat(string2.OrderBy(c => c)))
{
return true;
}
else
{
return false;
}
}
bool result = AreAnagrams("listen", "silent"); |
[
{
"role": "user",
"content": "Write a SQL query to find all the entries in a given table that contain a specific“value” in the given column."
},
{
"role": "assistant",
"content": "SELECT * \nFROM table \nWHERE col LIKE '%{value}%';"
}
] | Write a SQL query to find all the entries in a given table that contain a specific“value” in the given column. | SELECT *
FROM table
WHERE col LIKE '%{value}%'; | |
[
{
"role": "user",
"content": "Compare two values to check if the first one is greater than the second one, and if so, print \"A is greater than B\".\n\nA = 5\nB = 3"
},
{
"role": "assistant",
"content": "if A > B:\n print(\"A is greater than B\")"
}
] | Compare two values to check if the first one is greater than the second one, and if so, print "A is greater than B". | A = 5
B = 3 | if A > B:
print("A is greater than B") |
[
{
"role": "user",
"content": "List the combinations of two lists l1 and l2.\n\nlist l1 = [1, 2]\nlist l2 = [a, b]"
},
{
"role": "assistant",
"content": "[[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]"
}
] | List the combinations of two lists l1 and l2. | list l1 = [1, 2]
list l2 = [a, b] | [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] |
[
{
"role": "user",
"content": "Give a function to get an array of n-dimensional vectors."
},
{
"role": "assistant",
"content": "def get_n_dimensional_vectors(n):\n vectors = [[0 for x in range(n)] for x in range(len(arr))] \n for vector in vectors:\n for i in range(n):\n ... | Give a function to get an array of n-dimensional vectors. | def get_n_dimensional_vectors(n):
vectors = [[0 for x in range(n)] for x in range(len(arr))]
for vector in vectors:
for i in range(n):
vector[i] = arr[i]
return vectors | |
[
{
"role": "user",
"content": "Write a web crawler in Python to extract only the text content from a given website."
},
{
"role": "assistant",
"content": "# import the necessary libraries\nimport requests\nfrom bs4 import BeautifulSoup\n\n# define the web crawler\ndef web_crawler(url):\n # mak... | Write a web crawler in Python to extract only the text content from a given website. | # import the necessary libraries
import requests
from bs4 import BeautifulSoup
# define the web crawler
def web_crawler(url):
# make the request to the specified url
page = requests.get(url)
page_content = page.content
# parse the received content
soup = BeautifulSoup(page_content, 'lxml')
text... | |
[
{
"role": "user",
"content": "Make a program to display the maximum, minimum and average of numbers in a list\n\n[1,2,3,4,5]"
},
{
"role": "assistant",
"content": "list = [1,2,3,4,5]\nlist_length = len(list)\nmax_val = max(list)\nmin_val = min(list)\navg_val = sum(list) / list_length\n\n# Displa... | Make a program to display the maximum, minimum and average of numbers in a list | [1,2,3,4,5] | list = [1,2,3,4,5]
list_length = len(list)
max_val = max(list)
min_val = min(list)
avg_val = sum(list) / list_length
# Display Output
print("Maximum: ", max_val)
print("Minimum: ", min_val)
print("Average: ", avg_val) |
[
{
"role": "user",
"content": "How can one manage memory in C++?"
},
{
"role": "assistant",
"content": "In C++, memory can be managed by allocating and deallocating memory dynamically. This can be done either manually, using the new and delete operators, or by the use of smart pointers and other ... | How can one manage memory in C++? | In C++, memory can be managed by allocating and deallocating memory dynamically. This can be done either manually, using the new and delete operators, or by the use of smart pointers and other library functions. One can also free up memory by deleting unneeded objects, or by taking advantage of resource-managing classe... | |
[
{
"role": "user",
"content": "Write a procedure in PL/SQL to find the sum of numbers from 1 to 10."
},
{
"role": "assistant",
"content": "create or replace procedure addNums(sum OUT NUMBER)\nbegin\n sum := 0;\n for i in 1 .. 10 loop\n sum := sum + i;\n end loop; \nend addNums;"
}
] | Write a procedure in PL/SQL to find the sum of numbers from 1 to 10. | create or replace procedure addNums(sum OUT NUMBER)
begin
sum := 0;
for i in 1 .. 10 loop
sum := sum + i;
end loop;
end addNums; | |
[
{
"role": "user",
"content": "Evaluate the polynomial f(x) = 4x^2 + 7x + 1 at x = -3."
},
{
"role": "assistant",
"content": "f(-3) = 4(-3)^2 + 7(-3) + 1 = -36 + 21 + 1 = -14"
}
] | Evaluate the polynomial f(x) = 4x^2 + 7x + 1 at x = -3. | f(-3) = 4(-3)^2 + 7(-3) + 1 = -36 + 21 + 1 = -14 | |
[
{
"role": "user",
"content": "Create an HTML page with a header containing the text \"Welcome to our website\"."
},
{
"role": "assistant",
"content": "<html>\n<head><title>Welcome to our website</title></head>\n <body>\n <h1>Welcome to our website</h1>\n </body>\n</html>"
}
] | Create an HTML page with a header containing the text "Welcome to our website". | <html>
<head><title>Welcome to our website</title></head>
<body>
<h1>Welcome to our website</h1>
</body>
</html> | |
[
{
"role": "user",
"content": "What is a ternary operator?"
},
{
"role": "assistant",
"content": "A ternary operator is a conditional expression operator that can be used to return one of two values based on the evaluation of a boolean expression. In Python, the ternary operator is written as a ?... | What is a ternary operator? | A ternary operator is a conditional expression operator that can be used to return one of two values based on the evaluation of a boolean expression. In Python, the ternary operator is written as a ? expression. For example, a ? b : c is a shorthand for "if a then b else c", where a is a boolean expression. | |
[
{
"role": "user",
"content": "Create an HTML page with a text input box, a submit button and a table to display the results."
},
{
"role": "assistant",
"content": "<html>\n <head>\n <title>Inputs</title>\n </head>\n <body>\n <form>\n <input type=\"text\" id=\"in... | Create an HTML page with a text input box, a submit button and a table to display the results. | <html>
<head>
<title>Inputs</title>
</head>
<body>
<form>
<input type="text" id="inputText">
<input type="submit" value="Submit">
</form>
<table>
<thead>
<tr>
<th>Input Text</th>
</tr>
... | |
[
{
"role": "user",
"content": "Calculate the determinant of the following matrix.\n\n[1, 3, 4],\n[5, 6, 7],\n[9, 8, 2]"
},
{
"role": "assistant",
"content": "The determinant of the matrix is -76."
}
] | Calculate the determinant of the following matrix. | [1, 3, 4],
[5, 6, 7],
[9, 8, 2] | The determinant of the matrix is -76. |
[
{
"role": "user",
"content": "How do you check if a given string is in a list?"
},
{
"role": "assistant",
"content": "You can check if a given string is in a list by using the \"in\" keyword. For example, if you have a list of strings [\"apple\", \"banana\", \"orange\"] and you want to check if ... | How do you check if a given string is in a list? | You can check if a given string is in a list by using the "in" keyword. For example, if you have a list of strings ["apple", "banana", "orange"] and you want to check if the string "banana" is in the list, you can use the following syntax:
if "banana" in lst:
print("String is in list") | |
[
{
"role": "user",
"content": "Convert the following code snippet from Python 2 code to Python 3 code.\n\nx = raw_input(\"What is your name? \")"
},
{
"role": "assistant",
"content": "x = input(\"What is your name? \")"
}
] | Convert the following code snippet from Python 2 code to Python 3 code. | x = raw_input("What is your name? ") | x = input("What is your name? ") |
[
{
"role": "user",
"content": "Create a MySQL query to select the records whose name fields begins with an \"A\"."
},
{
"role": "assistant",
"content": "SELECT * FROM table_name WHERE name LIKE 'A%';"
}
] | Create a MySQL query to select the records whose name fields begins with an "A". | SELECT * FROM table_name WHERE name LIKE 'A%'; | |
[
{
"role": "user",
"content": "Create a function that takes a string of brackets and checks if they are correctly matched or not."
},
{
"role": "assistant",
"content": "def check_brackets(bracket_string):\n \"\"\"\n Function that checks if bracket string is correctly matched.\n \"\"\"\n ... | Create a function that takes a string of brackets and checks if they are correctly matched or not. | def check_brackets(bracket_string):
"""
Function that checks if bracket string is correctly matched.
"""
stack = []
open_brackets = {'[', '{', '('}
close_brackets = {']', '}', ')'}
for bracket in bracket_string:
if bracket in open_brackets:
stack.append(bracket)
... | |
[
{
"role": "user",
"content": "Sum the numbers in the given array using reduce.\n\nnumbers = [1, 2, 3, 4, 5]"
},
{
"role": "assistant",
"content": "# Sum the numbers in the given array using reduce\nfrom functools import reduce\n\nsum = reduce(lambda x, y: x + y, numbers)\n\nprint(sum) # Output: ... | Sum the numbers in the given array using reduce. | numbers = [1, 2, 3, 4, 5] | # Sum the numbers in the given array using reduce
from functools import reduce
sum = reduce(lambda x, y: x + y, numbers)
print(sum) # Output: 15 |
[
{
"role": "user",
"content": "Create a class in C++ that defines a number as a double value."
},
{
"role": "assistant",
"content": "// C++ Class\nclass Number {\nprivate:\n double num;\npublic:\n // Constructor\n Number(double val) : num(val) { }\n // Function to get the double value... | Create a class in C++ that defines a number as a double value. | // C++ Class
class Number {
private:
double num;
public:
// Constructor
Number(double val) : num(val) { }
// Function to get the double value
double getValue() {
return num;
}
}; | |
[
{
"role": "user",
"content": "Suggest an algorithm to compute the sum of all prime numbers from 2 to n."
},
{
"role": "assistant",
"content": "def sum_primes(n):\n # Initialize sum to 0\n sum_prime = 0\n\n # Iterate through all numbers from 0 to n\n for num in range(2, n+1):\n ... | Suggest an algorithm to compute the sum of all prime numbers from 2 to n. | def sum_primes(n):
# Initialize sum to 0
sum_prime = 0
# Iterate through all numbers from 0 to n
for num in range(2, n+1):
is_prime = True
# Check whether the number is prime
for div in range(2, num):
if num % div == 0:
is_prime = False
... | |
[
{
"role": "user",
"content": "Insert a breakpoint just before the return statement.\n\ndef calculate_the_total(fruit_list):\n total = 0\n for item in fruit_list:\n total += item\n \n return total"
},
{
"role": "assistant",
"content": "def calculate_the_total(fruit_list):\n total =... | Insert a breakpoint just before the return statement. | def calculate_the_total(fruit_list):
total = 0
for item in fruit_list:
total += item
return total | def calculate_the_total(fruit_list):
total = 0
for item in fruit_list:
total += item
import pdb; pdb.set_trace()
return total |
[
{
"role": "user",
"content": "Write a Python function to calculate the sum of the areas of a given list of circles, where each circle is defined as a dictionary containing 'radius' and 'x' as keys.\n\n[{'radius': 3, 'x': 5}, {'radius': 4, 'x': 7}, {'radius': 5, 'x': 9}]"
},
{
"role": "assistant",
... | Write a Python function to calculate the sum of the areas of a given list of circles, where each circle is defined as a dictionary containing 'radius' and 'x' as keys. | [{'radius': 3, 'x': 5}, {'radius': 4, 'x': 7}, {'radius': 5, 'x': 9}] | def sum_areas(circles):
total = 0
for circle in circles:
area = 3.14 * circle['radius'] ** 2
total += area
return total |
[
{
"role": "user",
"content": "Create a class in C++ for a light emitting diode (LED) object that describes the color of the LED."
},
{
"role": "assistant",
"content": "class LED \n{ \n private: \n int color; \n\npublic: \n // default constructor \n LED() \n { \n color = 0; ... | Create a class in C++ for a light emitting diode (LED) object that describes the color of the LED. | class LED
{
private:
int color;
public:
// default constructor
LED()
{
color = 0;
}
// setter function
void setColor(int c)
{
color = c;
}
// getter function
int getColor()
{
return color;
}
}; | |
[
{
"role": "user",
"content": "Assign the values of list_2 to the same positions of list_1.\n\nlist_1 = [1, 2, 5, 8]\nlist_2 = [3, 6, 9, 12]"
},
{
"role": "assistant",
"content": "list_1[0] = 3\nlist_1[1] = 6\nlist_1[2] = 9\nlist_1[3] = 12"
}
] | Assign the values of list_2 to the same positions of list_1. | list_1 = [1, 2, 5, 8]
list_2 = [3, 6, 9, 12] | list_1[0] = 3
list_1[1] = 6
list_1[2] = 9
list_1[3] = 12 |
[
{
"role": "user",
"content": "Write a Java code snippet to print the following line of text: “Hello, World!”"
},
{
"role": "assistant",
"content": "System.out.println(\"Hello, World!\");"
}
] | Write a Java code snippet to print the following line of text: “Hello, World!” | System.out.println("Hello, World!"); | |
[
{
"role": "user",
"content": "Create a CSS style to display text in italics."
},
{
"role": "assistant",
"content": "p {\n font-style: italic;\n}"
}
] | Create a CSS style to display text in italics. | p {
font-style: italic;
} | |
[
{
"role": "user",
"content": "Create a Python class that encodes a given number using the Base58 algorithm.\n\nnumber = 123456789"
},
{
"role": "assistant",
"content": "class Base58Encoder:\n '''This class encodes numbers using the Base58 algorithm'''\n def __init__(self,number):\n ... | Create a Python class that encodes a given number using the Base58 algorithm. | number = 123456789 | class Base58Encoder:
'''This class encodes numbers using the Base58 algorithm'''
def __init__(self,number):
self.number = number
def encode(self):
encoded = ""
alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
while self.number > 0:
re... |
[
{
"role": "user",
"content": "Construct a basic data structure to store a dictionary of words and their definitions."
},
{
"role": "assistant",
"content": "class WordDictionary(object): \n def __init__(self): \n self.words = {} \n\n def add_definition(self, word, definition): \n ... | Construct a basic data structure to store a dictionary of words and their definitions. | class WordDictionary(object):
def __init__(self):
self.words = {}
def add_definition(self, word, definition):
self.words[word] = definition
def lookup_definition(self, word):
if word in self.words:
return self.words[word]
else:
return None
... | |
[
{
"role": "user",
"content": "Create an object in Ruby that stores a student's name, age, and GPA."
},
{
"role": "assistant",
"content": "student = {\n name: \"John Smith\",\n age: 22,\n gpa: 3.5\n}"
}
] | Create an object in Ruby that stores a student's name, age, and GPA. | student = {
name: "John Smith",
age: 22,
gpa: 3.5
} | |
[
{
"role": "user",
"content": "Write a Java method that takes a string and an integer as input, and returns the string in reverse with the integer repeated at the end.\n\ninputString: \"Hello\"\nnum: 3"
},
{
"role": "assistant",
"content": "public static String repeatNumAtEnd(String inputString, ... | Write a Java method that takes a string and an integer as input, and returns the string in reverse with the integer repeated at the end. | inputString: "Hello"
num: 3 | public static String repeatNumAtEnd(String inputString, int num) {
String outputString = "";
for(int i = inputString.length() - 1; i >= 0; i--){
outputString += inputString.charAt(i);
}
for (int i = 0; i < num; i++){
outputString += num;
}
return outputString;
} |
[
{
"role": "user",
"content": "Determine whether two given arrays are equal or not.\n\narr1 = [1, 2, 3]\narr2 = [1, 2, 4]"
},
{
"role": "assistant",
"content": "The two arrays are not equal."
}
] | Determine whether two given arrays are equal or not. | arr1 = [1, 2, 3]
arr2 = [1, 2, 4] | The two arrays are not equal. |
[
{
"role": "user",
"content": "Given a comma-separated string with numbers, remove the max value from it and output a string with comma-separated values\n\n8, 12, 5, 2, 18"
},
{
"role": "assistant",
"content": "\"8, 12, 5, 2\""
}
] | Given a comma-separated string with numbers, remove the max value from it and output a string with comma-separated values | 8, 12, 5, 2, 18 | "8, 12, 5, 2" |
[
{
"role": "user",
"content": "Create a Javascript function to convert an array of integers into a new array of strings.\n\n[3, 6, 9]"
},
{
"role": "assistant",
"content": "function intToString(arr){\n var strings = [];\n for(let i = 0; i < arr.length; i++) {\n strings.push(arr[i].toString()... | Create a Javascript function to convert an array of integers into a new array of strings. | [3, 6, 9] | function intToString(arr){
var strings = [];
for(let i = 0; i < arr.length; i++) {
strings.push(arr[i].toString());
}
return strings;
} |
[
{
"role": "user",
"content": "Write a SQL query to find the average population of a city.\n\nTable \"Cities\":\ncity_name | population\n--------------------------\nNew_York | 8000000\nLondon | 9000000\nBerlin | 700000"
},
{
"role": "assistant",
"content": "SELECT AVG(population) FROM Cit... | Write a SQL query to find the average population of a city. | Table "Cities":
city_name | population
--------------------------
New_York | 8000000
London | 9000000
Berlin | 700000 | SELECT AVG(population) FROM Cities; |
[
{
"role": "user",
"content": "Given a list of integers, write a function in Python to sort and reverse the list.\n\ninput_list = [3, 8, 10, 1, 9]"
},
{
"role": "assistant",
"content": "def sort_and_reverse(list): \n res_list = sorted(list, reverse=True) \n return res_list \n \nsort_and_revers... | Given a list of integers, write a function in Python to sort and reverse the list. | input_list = [3, 8, 10, 1, 9] | def sort_and_reverse(list):
res_list = sorted(list, reverse=True)
return res_list
sort_and_reverse(input_list)
# Output
[10, 9, 8, 3, 1] |
[
{
"role": "user",
"content": "What HTML code is needed to print each item in the following list?\n\nlist = [\"apple\", \"banana\", \"cherry\"]"
},
{
"role": "assistant",
"content": "<ul>\n <li>apple</li>\n <li>banana</li>\n <li>cherry</li>\n</ul>"
}
] | What HTML code is needed to print each item in the following list? | list = ["apple", "banana", "cherry"] | <ul>
<li>apple</li>
<li>banana</li>
<li>cherry</li>
</ul> |
[
{
"role": "user",
"content": "Generate a code in C to check if a sentence is a palindrome.\n\nchar str[] = \"amanama\""
},
{
"role": "assistant",
"content": "#include <stdio.h> \n#include <string.h> \n\n// Function to check if a string is palindrome \nbool isPalindrome(char str[]) \n{ \n\t// Sta... | Generate a code in C to check if a sentence is a palindrome. | char str[] = "amanama" | #include <stdio.h>
#include <string.h>
// Function to check if a string is palindrome
bool isPalindrome(char str[])
{
// Start from leftmost and rightmost corners of str
int l = 0;
int h = strlen(str)-1;
// Keep comparing characters while they are same
while (h > l)
{
if (str[l++] != str[h--])
... |
[
{
"role": "user",
"content": "Construct an SQL query to display the titles of movies with more than 10 awards."
},
{
"role": "assistant",
"content": "SELECT Title \nFROM Movies \nWHERE Awards > 10;"
}
] | Construct an SQL query to display the titles of movies with more than 10 awards. | SELECT Title
FROM Movies
WHERE Awards > 10; | |
[
{
"role": "user",
"content": "Modify the following code to output Odd numbers from 1 to 10\n\nfor num in range(1, 10):\n print( num )"
},
{
"role": "assistant",
"content": "for num in range(1, 10):\n if num % 2 == 1:\n print( num )"
}
] | Modify the following code to output Odd numbers from 1 to 10 | for num in range(1, 10):
print( num ) | for num in range(1, 10):
if num % 2 == 1:
print( num ) |
[
{
"role": "user",
"content": "Generate a function that takes an array of integers and rearranges the elements in a cyclical fashion, such that the element at index 0 comes last, the element at index 1 goes to the front, the element at index 2 is inserted after the element at the last index and so on.\n\narr... | Generate a function that takes an array of integers and rearranges the elements in a cyclical fashion, such that the element at index 0 comes last, the element at index 1 goes to the front, the element at index 2 is inserted after the element at the last index and so on. | arr = [1, 2, 3, 4, 5] | def rearrange_array(arr):
output = []
for i in range(len(arr)):
idx = (i + 1) % len(arr)
output.append(arr[idx])
return output |
[
{
"role": "user",
"content": "Edit the following HTML code to add an additional radio button with the label \"orange\".\n\n<input type=\"radio\" name=\"fruit\" value=\"apple\"> Apple<br>\n<input type=\"radio\" name=\"fruit\" value=\"banana\"> Banana"
},
{
"role": "assistant",
"content": "<input ... | Edit the following HTML code to add an additional radio button with the label "orange". | <input type="radio" name="fruit" value="apple"> Apple<br>
<input type="radio" name="fruit" value="banana"> Banana | <input type="radio" name="fruit" value="apple"> Apple<br>
<input type="radio" name="fruit" value="banana"> Banana<br>
<input type="radio" name="fruit" value="orange"> Orange |
[
{
"role": "user",
"content": "Compute the absolute difference between two given numbers.\n\nx = 7\ny = 4"
},
{
"role": "assistant",
"content": "diff = abs(x - y)\nprint(diff) # output: 3"
}
] | Compute the absolute difference between two given numbers. | x = 7
y = 4 | diff = abs(x - y)
print(diff) # output: 3 |
[
{
"role": "user",
"content": "Write a SQL query to find the employee names who are working in the company since Jan 2019."
},
{
"role": "assistant",
"content": "SELECT employee_name FROM employees WHERE start_date >= '2019-01-01'"
}
] | Write a SQL query to find the employee names who are working in the company since Jan 2019. | SELECT employee_name FROM employees WHERE start_date >= '2019-01-01' | |
[
{
"role": "user",
"content": "Write a function to extract a specific key from a dictionary.\n\n{'a':1, 'b':2, 'c':3}"
},
{
"role": "assistant",
"content": "def extract_key(dictionary, key):\n return dictionary.get(key)"
}
] | Write a function to extract a specific key from a dictionary. | {'a':1, 'b':2, 'c':3} | def extract_key(dictionary, key):
return dictionary.get(key) |
[
{
"role": "user",
"content": "Describe the purpose of an iterator class in Java."
},
{
"role": "assistant",
"content": "An iterator class in Java is used to traverse through a collection to access its elements. It allows for the convenient looping and retrieval of elements from the collection in... | Describe the purpose of an iterator class in Java. | An iterator class in Java is used to traverse through a collection to access its elements. It allows for the convenient looping and retrieval of elements from the collection in an orderly fashion. | |
[
{
"role": "user",
"content": "Write code that adds two numbers using the unary operator."
},
{
"role": "assistant",
"content": "// Function to add two numbers using unary operator \nint addNumbers(int x, int y) \n{ \n // Iterate till there is no carry \n while (y != 0) \n { \n //... | Write code that adds two numbers using the unary operator. | // Function to add two numbers using unary operator
int addNumbers(int x, int y)
{
// Iterate till there is no carry
while (y != 0)
{
// carry now contains common
// set bits of x and y
int carry = x & y;
// Sum of bits of x and y where at
// least one of... | |
[
{
"role": "user",
"content": "Rewrite the following Python code without using the 'list comprehension' syntax.\n\n[x * x for x in range(5)]"
},
{
"role": "assistant",
"content": "list_result = []\nfor x in range(5):\n list_result.append(x*x)"
}
] | Rewrite the following Python code without using the 'list comprehension' syntax. | [x * x for x in range(5)] | list_result = []
for x in range(5):
list_result.append(x*x) |
[
{
"role": "user",
"content": "Create a variable in Python to store 10 multidimensional arrays."
},
{
"role": "assistant",
"content": "arrays = [[[1,2], [3,4]],\n [[5,6], [7,8]],\n [[9,10], [11,12]],\n [[13,14], [15,16]],\n [[17,18], [19,20]],\n [[21,2... | Create a variable in Python to store 10 multidimensional arrays. | arrays = [[[1,2], [3,4]],
[[5,6], [7,8]],
[[9,10], [11,12]],
[[13,14], [15,16]],
[[17,18], [19,20]],
[[21,22], [23,24]],
[[25,26], [27,28]],
[[29,30], [31,32]],
[[33,34], [35,36]],
[[37,38], [39,40]]] | |
[
{
"role": "user",
"content": "How to create a loop in Python which will iterate over a list?"
},
{
"role": "assistant",
"content": "#Iterate over a list \nlist = [1, 2, 3, 4, 5]\n\nfor item in list:\n print(item)"
}
] | How to create a loop in Python which will iterate over a list? | #Iterate over a list
list = [1, 2, 3, 4, 5]
for item in list:
print(item) | |
[
{
"role": "user",
"content": "In the given string, split the words and remove empty strings.\n\nstring = \" Hello World \""
},
{
"role": "assistant",
"content": "def split_and_remove(string):\n \"\"\"In the given string, split the words and remove empty strings.\"\"\"\n # Split th... | In the given string, split the words and remove empty strings. | string = " Hello World " | def split_and_remove(string):
"""In the given string, split the words and remove empty strings."""
# Split the string by spaces
arr = string.split(' ')
# Initialize empty list
new_arr = []
# Iterate over array
for word in arr:
# Check if not empty
if word != '':
#... |
[
{
"role": "user",
"content": "Create a Node.js server which serves a static HTML page."
},
{
"role": "assistant",
"content": "// Import the necessary modules\nconst http = require('http');\nconst fs = require('fs');\n\n// Create a simple server which serves a static HTML page\nhttp.createServer(... | Create a Node.js server which serves a static HTML page. | // Import the necessary modules
const http = require('http');
const fs = require('fs');
// Create a simple server which serves a static HTML page
http.createServer((req, res) => {
fs.readFile('./index.html',(err, data) => {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
... | |
[
{
"role": "user",
"content": "Construct a Django model field for storing a user's age."
},
{
"role": "assistant",
"content": "age = models.IntegerField()"
}
] | Construct a Django model field for storing a user's age. | age = models.IntegerField() | |
[
{
"role": "user",
"content": "Comment on the following code:\n\nfunction power (base, exponent) {\n let result = 1;\n for (let count = 0; count < exponent; count++) {\n result *= base;\n }\n return result;\n}"
},
{
"role": "assistant",
"content": "// This function takes in two va... | Comment on the following code: | function power (base, exponent) {
let result = 1;
for (let count = 0; count < exponent; count++) {
result *= base;
}
return result;
} | // This function takes in two values, a base and an exponent, and calculates the power of the base with the exponent. The result is computed by multiplying the base with the exponent. The result is then returned to the caller. |
[
{
"role": "user",
"content": "Write an SQL query to find the list of products whose price is greater than 50."
},
{
"role": "assistant",
"content": "SELECT * \nFROM products\nWHERE price > 50;"
}
] | Write an SQL query to find the list of products whose price is greater than 50. | SELECT *
FROM products
WHERE price > 50; | |
[
{
"role": "user",
"content": "Construct a query in PostgreSQL to find the names and emails of all users who have \"google.com\" in their emails."
},
{
"role": "assistant",
"content": "SELECT name, email\nFROM users\nWHERE email LIKES '%google.com%';"
}
] | Construct a query in PostgreSQL to find the names and emails of all users who have "google.com" in their emails. | SELECT name, email
FROM users
WHERE email LIKES '%google.com%'; | |
[
{
"role": "user",
"content": "Write a function that takes in a string and returns a list of all the words that have more than 5 characters"
},
{
"role": "assistant",
"content": "def long_words(string):\n words = string.split()\n long_words_list = []\n for word in words:\n if len(... | Write a function that takes in a string and returns a list of all the words that have more than 5 characters | def long_words(string):
words = string.split()
long_words_list = []
for word in words:
if len(word) > 5:
long_words_list.append(word)
return long_words_list | |
[
{
"role": "user",
"content": "Update the strings stored in a dictionary, so that all strings have the same length.\n\nd = {\n 'apple': 'small',\n 'orange': 'medium size'\n}"
},
{
"role": "assistant",
"content": "d = {\n 'apple': 'small ',\n 'orange': 'medium size'\n }"
}
] | Update the strings stored in a dictionary, so that all strings have the same length. | d = {
'apple': 'small',
'orange': 'medium size'
} | d = {
'apple': 'small ',
'orange': 'medium size'
} |
[
{
"role": "user",
"content": "Combine the two lists below using Python to produce a single list containing all elements from both.\n\nlist_one = [1, 2, 3]\nlist_two = [4, 5, 6]"
},
{
"role": "assistant",
"content": "list_one = [1, 2, 3]\nlist_two = [4, 5, 6]\ncombined_list = list_one + list_two\... | Combine the two lists below using Python to produce a single list containing all elements from both. | list_one = [1, 2, 3]
list_two = [4, 5, 6] | list_one = [1, 2, 3]
list_two = [4, 5, 6]
combined_list = list_one + list_two
print(combined_list) # Output: [1, 2, 3, 4, 5, 6] |
[
{
"role": "user",
"content": "Implement a stack to store and retrieve items in last-in first-out order."
},
{
"role": "assistant",
"content": "class Stack:\n def __init__(self):\n self.items = []\n \n def push(self, item):\n self.items.append(item)\n \n def pop(self)... | Implement a stack to store and retrieve items in last-in first-out order. | class Stack:
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop()
def peek(self):
return self.items[len(self.items)-1]
def size(self):
return len(self.items) | |
[
{
"role": "user",
"content": "Generate a valid HTML page given the body contents.\n\n<h1>Hello World!</h1>\n<p>This is a simple HTML page.</p>"
},
{
"role": "assistant",
"content": "<html>\n <head>\n </head>\n <body>\n <h1>Hello World!</h1>\n <p>This is a simple HTML page.... | Generate a valid HTML page given the body contents. | <h1>Hello World!</h1>
<p>This is a simple HTML page.</p> | <html>
<head>
</head>
<body>
<h1>Hello World!</h1>
<p>This is a simple HTML page.</p>
</body>
</html> |
[
{
"role": "user",
"content": "Write a PHP script to fetch data from an API."
},
{
"role": "assistant",
"content": "<?php\n //Initialize cURL\n $curl = curl_init();\n\n //Set cURL parameters\n curl_setopt_array($curl, array(\n CURLOPT_URL => \"http://path.to/api/\",\n CURLOPT_RE... | Write a PHP script to fetch data from an API. | <?php
//Initialize cURL
$curl = curl_init();
//Set cURL parameters
curl_setopt_array($curl, array(
CURLOPT_URL => "http://path.to/api/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array("Content-type: application/json")
));
//Execute cURL
$response = curl_exec($curl)... | |
[
{
"role": "user",
"content": "Create a SQL query which returns the records from the following table only for the year 2010.\n\nTable name: Record"
},
{
"role": "assistant",
"content": "SELECT * FROM Record WHERE year = 2010;"
}
] | Create a SQL query which returns the records from the following table only for the year 2010. | Table name: Record | SELECT * FROM Record WHERE year = 2010; |
[
{
"role": "user",
"content": "Write the SQL query to delete all tables from a given database.\n\ndatabase: testdb"
},
{
"role": "assistant",
"content": "DROP DATABASE testdb;"
}
] | Write the SQL query to delete all tables from a given database. | database: testdb | DROP DATABASE testdb; |
[
{
"role": "user",
"content": "Formulate a query in SQL to return the name and address of all customers who have placed an order in the last month."
},
{
"role": "assistant",
"content": "SELECT name, address FROM customers JOIN orders ON customers.id = orders.customer_id WHERE orders.date > DATE_... | Formulate a query in SQL to return the name and address of all customers who have placed an order in the last month. | SELECT name, address FROM customers JOIN orders ON customers.id = orders.customer_id WHERE orders.date > DATE_SUB(NOW(), INTERVAL 1 MONTH); | |
[
{
"role": "user",
"content": "Complete the following HTML template with appropriate tags:\n\n<html>\n<head> \n</head>\n<body>\n\n</body>\n</html>"
},
{
"role": "assistant",
"content": "<html>\n<head> \n <title> Title of page </title>\n</head>\n<body>\n <h1> Header title </h1>\n <p> This is a ... | Complete the following HTML template with appropriate tags: | <html>
<head>
</head>
<body>
</body>
</html> | <html>
<head>
<title> Title of page </title>
</head>
<body>
<h1> Header title </h1>
<p> This is a sample content of a web page. </p>
</body>
</html> |
[
{
"role": "user",
"content": "Write an expression in JavaScript to calculate the perimeter of a triangle with sides 3, 4 and 5."
},
{
"role": "assistant",
"content": "var a = 3;\nvar b = 4;\nvar c = 5;\n\nvar perimeter = a + b + c; // 12"
}
] | Write an expression in JavaScript to calculate the perimeter of a triangle with sides 3, 4 and 5. | var a = 3;
var b = 4;
var c = 5;
var perimeter = a + b + c; // 12 | |
[
{
"role": "user",
"content": "Design a code snippet to sort a hashtable by its keys.\n\n{8: \"hello\", 3: \"goodbye\", 2: \"aloha\", 4: \"bonjour\", 6: \"ni hao\"}"
},
{
"role": "assistant",
"content": "// a function to sort the hashtable by its keys\nfunc sortHashTableKeys(hashTable map[int]str... | Design a code snippet to sort a hashtable by its keys. | {8: "hello", 3: "goodbye", 2: "aloha", 4: "bonjour", 6: "ni hao"} | // a function to sort the hashtable by its keys
func sortHashTableKeys(hashTable map[int]string) map[int]string {
// a slice to store the keys in order
var keys []int
for key := range hashTable {
keys = append(keys, key)
}
// sort the slice
sort.Ints(keys)
// create a new map ... |
[
{
"role": "user",
"content": "Identify the programming language of the sample code snippet.\n\ndef find_average(numbers):\n sum = 0\n for num in numbers:\n sum += num\n return sum / len(numbers)"
},
{
"role": "assistant",
"content": "Python."
}
] | Identify the programming language of the sample code snippet. | def find_average(numbers):
sum = 0
for num in numbers:
sum += num
return sum / len(numbers) | Python. |
[
{
"role": "user",
"content": "Create an application to hide certain words in a text.\n\nText: \"The quick brown fox jumped over the lazy dog.\"\nWords to hide: [\"fox\", \"dog\"]"
},
{
"role": "assistant",
"content": "const censoredText = (text, wordsToHide) => {\n const wordsArr = text.split('... | Create an application to hide certain words in a text. | Text: "The quick brown fox jumped over the lazy dog."
Words to hide: ["fox", "dog"] | const censoredText = (text, wordsToHide) => {
const wordsArr = text.split(' ');
wordsArr.forEach((word, index) => {
if (wordsToHide.includes(word)) {
wordsArr[index] = '*'.repeat(word.length)
}
});
return wordsArr.join(' ');
}
censoredText("The quick brown fox jumped over the lazy dog.", ["fox"... |
[
{
"role": "user",
"content": "Create a python script that takes three required parameters 'x', 'y' and 'z' and prints the result of x * y * z\n\nx=4\ny=3\nz=2"
},
{
"role": "assistant",
"content": "def multiply(x, y, z):\n return x * y * z\n \nprint(multiply(4, 3, 2)) //output 24"
}
] | Create a python script that takes three required parameters 'x', 'y' and 'z' and prints the result of x * y * z | x=4
y=3
z=2 | def multiply(x, y, z):
return x * y * z
print(multiply(4, 3, 2)) //output 24 |
[
{
"role": "user",
"content": "Create a program to generate all possible pairs of a given list of numbers\n\n[1, 2, 3]"
},
{
"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 = []\n ... | Create a program to generate all possible pairs of a given list of numbers | [1, 2, 3] | """
Create a program to generate all possible pairs of a given list of numbers
"""
def generate_pairs(nums):
pairs = []
for i in range(len(nums)):
for j in range(i+1, len(nums)):
pairs.append((nums[i], nums[j]))
return pairs
if __name__ == '__main__':
print(generate_pairs([1, 2, 3]... |
[
{
"role": "user",
"content": "Create a Java program to count and print the distinct elements in an array.\n\nint[] arr = {1, 2, 3, 2, 1, 4, 3, 2}"
},
{
"role": "assistant",
"content": "public class DistinctElements { \n public static void main(String[] args) { \n int[] arr = {1, 2, 3, ... | Create a Java program to count and print the distinct elements in an array. | int[] arr = {1, 2, 3, 2, 1, 4, 3, 2} | public class DistinctElements {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 2, 1, 4, 3, 2};
// Initialize all element with the value 0.
int[] temp = new int[arr.length];
int visited = -1;
for (int i = 0; i < arr.length; i++) {
int c... |
[
{
"role": "user",
"content": "Write a JavaScript code to print the characters of a string one by one in an alert message.\n\nstr = \"Hello World!\""
},
{
"role": "assistant",
"content": "for (let i = 0; i < str.length; i++) {\n alert(str.charAt(i));\n}"
}
] | Write a JavaScript code to print the characters of a string one by one in an alert message. | str = "Hello World!" | for (let i = 0; i < str.length; i++) {
alert(str.charAt(i));
} |
[
{
"role": "user",
"content": "Create an Android application with a Button and a TextView. When the button is clicked, the TextView should be populated with the text \"Hello, World!\"."
},
{
"role": "assistant",
"content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<androidx.constraintlayout.wi... | Create an Android application with a Button and a TextView. When the button is clicked, the TextView should be populated with the text "Hello, World!". | <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_heigh... | |
[
{
"role": "user",
"content": "Modify the below HTML code to make the text show with a different font and font size.\n\n<p>This text should be different</p>"
},
{
"role": "assistant",
"content": "<p style=\"font-family: Helvetica, sans-serif; font-size: 30px\">This text should be different</p>"
... | Modify the below HTML code to make the text show with a different font and font size. | <p>This text should be different</p> | <p style="font-family: Helvetica, sans-serif; font-size: 30px">This text should be different</p> |
[
{
"role": "user",
"content": "Construct a linked list data structure in C language."
},
{
"role": "assistant",
"content": "#include <stdio.h>\n#include <stdlib.h>\n \n// Node of a linked list\nstruct Node \n{\n int data;\n struct Node *next;\n};\n \n// Function to create a new node\nstruct... | Construct a linked list data structure in C language. | #include <stdio.h>
#include <stdlib.h>
// Node of a linked list
struct Node
{
int data;
struct Node *next;
};
// Function to create a new node
struct Node *newnode(int data)
{
struct Node *temp = (struct Node*)malloc(sizeof(struct Node));
temp->data = data;
temp->next = NULL;
return temp;
}... | |
[
{
"role": "user",
"content": "Find the mean of the elements in this array.\n\nArray: [2, 3, 5, 4, 9]"
},
{
"role": "assistant",
"content": "The mean of the elements in this array is 4.8."
}
] | Find the mean of the elements in this array. | Array: [2, 3, 5, 4, 9] | The mean of the elements in this array is 4.8. |
[
{
"role": "user",
"content": "Given a list of integers, write a program to check if there exist any pairs of numbers that sum to a given number.\n\nv = [2, 3, 4, 9], sum = 8"
},
{
"role": "assistant",
"content": "def findSumPairs(v, sum): \n v.sort()\n l = 0\n r = len(v) - 1\n while... | Given a list of integers, write a program to check if there exist any pairs of numbers that sum to a given number. | v = [2, 3, 4, 9], sum = 8 | def findSumPairs(v, sum):
v.sort()
l = 0
r = len(v) - 1
while l < r:
if v[l] + v[r] == sum:
return True
elif v[l] + v[r] > sum:
r -= 1
else:
l += 1
return False
v = [2, 3, 4, 9]
sum = 8
print(findSumPairs(v, sum)) |
[
{
"role": "user",
"content": "Suggest a Pandas DataFrame command to remove element duplicates from a given dataframe."
},
{
"role": "assistant",
"content": "df.drop_duplicates()"
}
] | Suggest a Pandas DataFrame command to remove element duplicates from a given dataframe. | df.drop_duplicates() | |
[
{
"role": "user",
"content": "Edit the code to make sure the output error messages are informative.\n\ndef myfunc(param):\n if type(param) != str:\n print(f\"{param} is not valid input type\")"
},
{
"role": "assistant",
"content": "def myfunc(param):\n if not isinstance(param, str):\n pr... | Edit the code to make sure the output error messages are informative. | def myfunc(param):
if type(param) != str:
print(f"{param} is not valid input type") | def myfunc(param):
if not isinstance(param, str):
print(f"Expected a string for parameter 'param' but received type '{type(param).__name__}'") |
[
{
"role": "user",
"content": "Given a string, write a regular expression to extract the last three words of the string.\n\ntext = \"My name is Bill Gates\""
},
{
"role": "assistant",
"content": "reg = r\"(\\w+(\\s\\w+){2}$)\""
}
] | Given a string, write a regular expression to extract the last three words of the string. | text = "My name is Bill Gates" | reg = r"(\w+(\s\w+){2}$)" |
[
{
"role": "user",
"content": "Write an HTML program to capture the entered text in an input box"
},
{
"role": "assistant",
"content": "<html> \n <head>\n <title>Text Capturing</title>\n </head>\n \n <script>\n function captureText() {\n var text = document.getElementById(\"inputBox... | Write an HTML program to capture the entered text in an input box | <html>
<head>
<title>Text Capturing</title>
</head>
<script>
function captureText() {
var text = document.getElementById("inputBox").value;
alert("Entered text: " + text);
}
</script>
<body>
<h1> Text Capturing </h1>
<input type="text" id="inputBox" />
<button onclick=... | |
[
{
"role": "user",
"content": "Write a C# code to print the first n terms of the Series 0, 1, 2, 6, 42, 1806."
},
{
"role": "assistant",
"content": "static void printSeries(int n) \n{ \n \n int a = 0, b = 1, c = 2; \n \n Console.Write(a + \" \" + b + \" \" + c + \" \"); \n \n for (int... | Write a C# code to print the first n terms of the Series 0, 1, 2, 6, 42, 1806. | static void printSeries(int n)
{
int a = 0, b = 1, c = 2;
Console.Write(a + " " + b + " " + c + " ");
for (int i = 3; i < n; i++)
{
int d = 2 * c + (a + b);
Console.Write(d + " ");
a = b;
b = c;
c = d;
}
} | |
[
{
"role": "user",
"content": "Using the provided snippet of code below, create a function in Java to convert a given array of strings to lowercase."
},
{
"role": "assistant",
"content": "public static String[] toLowerCase(String[] words) {\n String[] lowerWords = new String[words.length];\n ... | Using the provided snippet of code below, create a function in Java to convert a given array of strings to lowercase. | public static String[] toLowerCase(String[] words) {
String[] lowerWords = new String[words.length];
for (int i = 0; i < words.length; i++)
lowerWords[i] = words[i].toLowerCase();
return lowerWords;
} | |
[
{
"role": "user",
"content": "Write a Python script that prints the current date and time."
},
{
"role": "assistant",
"content": "from datetime import datetime\n\nnow = datetime.now()\nprint(now.strftime(\"%d-%m-%Y %H:%M:%S\"))"
}
] | Write a Python script that prints the current date and time. | from datetime import datetime
now = datetime.now()
print(now.strftime("%d-%m-%Y %H:%M:%S")) | |
[
{
"role": "user",
"content": "Write a code to delete a node from a given BST."
},
{
"role": "assistant",
"content": "# Node class to define a node of a BST \nclass Node(object): \n \n # Constructor \n def __init__(self, data): \n self.data = data \n self.left = None\n ... | Write a code to delete a node from a given BST. | # Node class to define a node of a BST
class Node(object):
# Constructor
def __init__(self, data):
self.data = data
self.left = None
self.right = None
# Function to delete a given node from BST
def delete_node(root, key):
# base case
if root is None:
ret... | |
[
{
"role": "user",
"content": "Identify the salient feature in the given piece of code.\n\ndef func(x, y):\n z = x + y\n print(z)\n return x - y"
},
{
"role": "assistant",
"content": "The salient feature of the given code is that it both prints a result and returns a value."
}
] | Identify the salient feature in the given piece of code. | def func(x, y):
z = x + y
print(z)
return x - y | The salient feature of the given code is that it both prints a result and returns a value. |
[
{
"role": "user",
"content": "Create a SQL query that returns the names and salaries of all employees who are earning more than $100,000.\n\nEmployees table \ncolumns: id | name | salary\n\n1 | John | 120000\n2 | Jane | 150000\n3 | Jack | 160000"
},
{
"role": "assistant",
"content": "SELECT name... | Create a SQL query that returns the names and salaries of all employees who are earning more than $100,000. | Employees table
columns: id | name | salary
1 | John | 120000
2 | Jane | 150000
3 | Jack | 160000 | SELECT name, salary FROM Employees WHERE salary > 100000; |
[
{
"role": "user",
"content": "Calculate the area of a triangle given three side lengths."
},
{
"role": "assistant",
"content": "def calculate_area_triangle(a, b, c):\n s = (a + b + c) / 2\n return (s*(s-a)*(s-b)*(s-c)) ** 0.5"
}
] | Calculate the area of a triangle given three side lengths. | def calculate_area_triangle(a, b, c):
s = (a + b + c) / 2
return (s*(s-a)*(s-b)*(s-c)) ** 0.5 | |
[
{
"role": "user",
"content": "Develop an algorithm to find the depth in a tree."
},
{
"role": "assistant",
"content": "def tree_depth(root): \n if root is None: \n return 0 ; \n \n else : \n left_height = tree_depth(root.left) \n right_height = tree_depth(root.right... | Develop an algorithm to find the depth in a tree. | def tree_depth(root):
if root is None:
return 0 ;
else :
left_height = tree_depth(root.left)
right_height = tree_depth(root.right)
if (left_height > right_height):
return left_height+1
else:
return right_height+1 | |
[
{
"role": "user",
"content": "Create a CSS rule to set the body's font size to 12px."
},
{
"role": "assistant",
"content": "body {\n font-size: 12px;\n}"
}
] | Create a CSS rule to set the body's font size to 12px. | body {
font-size: 12px;
} | |
[
{
"role": "user",
"content": "Define a function which can generate a list of 15 random numbers between 1 to 30."
},
{
"role": "assistant",
"content": "\"\"\"\nDefine a function which can generate a list of 15 random numbers between 1 to 30\n\"\"\"\nimport random\n\ndef generate_random_list():\n ... | Define a function which can generate a list of 15 random numbers between 1 to 30. | """
Define a function which can generate a list of 15 random numbers between 1 to 30
"""
import random
def generate_random_list():
return [random.randint(1,30) for _ in range(15)]
if __name__ == '__main__':
print(generate_random_list()) | |
[
{
"role": "user",
"content": "Write a code snippet to convert a list in Python to a set.\n\nlist1 = [1,2,3,4,5]"
},
{
"role": "assistant",
"content": "set1 = set(list1) # set1 will now contain [1,2,3,4,5]"
}
] | Write a code snippet to convert a list in Python to a set. | list1 = [1,2,3,4,5] | set1 = set(list1) # set1 will now contain [1,2,3,4,5] |
[
{
"role": "user",
"content": "Write JavaScript code to add the following data to the web page.\n\n[\n { name: \"John\", age: 25 },\n { name: \"Rob\", age: 27 },\n { name: \"Mia\", age: 22 }\n]"
},
{
"role": "assistant",
"content": "let data = [\n { name: \"John\", age: 25... | Write JavaScript code to add the following data to the web page. | [
{ name: "John", age: 25 },
{ name: "Rob", age: 27 },
{ name: "Mia", age: 22 }
] | let data = [
{ name: "John", age: 25 },
{ name: "Rob", age: 27 },
{ name: "Mia", age: 22 }
];
let table = document.createElement("table");
table.setAttribute("id", "personTable");
let thead = document.createElement("thead");
let tr = document.createElement("tr");
let th = document.createElement("th");
th.... |
[
{
"role": "user",
"content": "Suggest a sorting algorithm that is suitable for a large, unsorted integer array."
},
{
"role": "assistant",
"content": "The Merge Sort algorithm is suitable for a large, unsorted integer array. It is a divide and conquer algorithm, which divides the array into two ... | Suggest a sorting algorithm that is suitable for a large, unsorted integer array. | The Merge Sort algorithm is suitable for a large, unsorted integer array. It is a divide and conquer algorithm, which divides the array into two halves, recursively sorts them, and then merges them together. It has a time complexity of O(n log n). | |
[
{
"role": "user",
"content": "Write a CSS style to give a border of 3 pixels to the HTML element."
},
{
"role": "assistant",
"content": "html {\n border: 3px solid black;\n}"
}
] | Write a CSS style to give a border of 3 pixels to the HTML element. | html {
border: 3px solid black;
} | |
[
{
"role": "user",
"content": "How do the following Java methods work?\n\npublic static void main(String[] args) \n{ \n int[] arr = {2,4,6,8,10}; \n int n = 2; \n int result = binarySearch(arr, 0, arr.length-1, n); \n if (result == -1) \n System.out.println(\"Element is not present\"); \n ... | How do the following Java methods work? | public static void main(String[] args)
{
int[] arr = {2,4,6,8,10};
int n = 2;
int result = binarySearch(arr, 0, arr.length-1, n);
if (result == -1)
System.out.println("Element is not present");
else
System.out.println("Element is present at index " +
... | The main method takes an array of integers and an element to search for. It calls binarySearch method which uses the binary search algorithm to search for the element in the given array. The algorithm starts by calculating the mid point of the given array. If the element at the mid point is equal to the element to sear... |
[
{
"role": "user",
"content": "Write an SQL query to get the name and date of birth of all the people born in the year 1975."
},
{
"role": "assistant",
"content": "SELECT name, date_of_birth \nFROM people \nWHERE YEAR(date_of_birth) = '1975';"
}
] | Write an SQL query to get the name and date of birth of all the people born in the year 1975. | SELECT name, date_of_birth
FROM people
WHERE YEAR(date_of_birth) = '1975'; | |
[
{
"role": "user",
"content": "Create a JavaScript function to return the greatest value from the following array of numbers.\n\n[2, 4, 8, 10, 15]"
},
{
"role": "assistant",
"content": "function getGreatestValue(arr) {\n let greatest = arr[0];\n for(let i = 0; i < arr.length; i++) {\n if(arr... | Create a JavaScript function to return the greatest value from the following array of numbers. | [2, 4, 8, 10, 15] | function getGreatestValue(arr) {
let greatest = arr[0];
for(let i = 0; i < arr.length; i++) {
if(arr[i] > greatest) {
greatest = arr[i];
}
}
return greatest;
} |
CodeAlpaca OpenAI Native
This is a deterministic, lossless-formatting derivative of
sahil2801/CodeAlpaca-20k,
modernized with a typed OpenAI/TRL messages column and decontaminated against
the HumanEval and MBPP test sets. The original Alpaca columns remain available
for backward compatibility.
Intended use
from datasets import load_dataset
from trl import SFTTrainer
dataset = load_dataset("Archangel-system/codealpaca-openai-native")
trainer = SFTTrainer(model="your-model", train_dataset=dataset["train"])
No row-level JSON parsing or prompt concatenation is required. Choose a model whose tokenizer has an appropriate chat template.
Schema and conversion rule
Each row has:
messages: a typed list of two records, strictlyuserthenassistant;instruction,input, andoutput: the unchanged source strings.
The user message equals instruction when input.strip() is empty. Otherwise
it equals instruction + "\n\n" + input (exactly two newline characters).
The assistant message equals output. No answer was rewritten or generated.
Source audit
The build downloaded the source's Hub auto-converted Parquet shard directly.
| Measurement | Count |
|---|---|
| Source rows | 20022 |
Non-empty input rows |
10258 |
Empty output rows |
6 |
| Exact duplicate instruction rows | 0 |
| Aggressively normalized duplicate instruction rows | 0 |
Exact output == instruction rows |
0 |
Normalized output == instruction rows |
0 |
Decontamination
Two criteria are applied to CodeAlpaca instruction strings against benchmark
test prompts. The benchmark sets are never modified.
- Exact normalized equality:
re.sub(r"[^a-z0-9]+", "", s.lower()). - Shared 13-gram after lowercasing and tokenizing with
[a-z0-9]+.
| Benchmark | Test items | Exact-normalized source rows | 13-gram source rows |
|---|---|---|---|
| HumanEval | 164 | 0 | 0 |
MBPP (full, test, field text) |
500 | 1 | 2 |
Any source row matching either criterion was removed before splitting. Complete
row-to-benchmark evidence is in rejections.jsonl. A row touching multiple
items or criteria is rejected once but retains every hit in that log.
Filtering, deduplication, and split
| Stage / reason | Rows removed |
|---|---|
| Empty output | 6 |
| Benchmark contamination (union) | 2 |
Duplicate normalized (instruction, input) |
0 |
| Train/test signature purge from train | 0 |
| Total removed | 8 |
| Rejection rate | 0.0400% |
Rows are deduplicated on the tuple (normalize_text(instruction), normalize_text(input)), where normalize_text is the same exact-normalization
function used by verification. The first source occurrence is retained.
The remaining rows are shuffled with Python's random.Random(42). The test
size is min(1000, round(0.05 * n)); test receives the first shuffled indices.
Any normalized pair crossing train/test would be purged from train, never
test. The measured post-build intersection is 0.
| Split | Rows |
|---|---|
| train | 19014 |
| test | 1000 |
| total | 20014 |
Lengths and diversity
Lengths below are lexical token counts using [a-z0-9]+.
| Field | Min | Median | Mean | P95 | Max |
|---|---|---|---|---|---|
| User message | 4 | 16.0 | 17.5716 | 31.0 | 110 |
| Assistant message | 0 | 20.0 | 28.4568 | 82.0 | 633 |
The final dataset contains 20014
exactly unique instructions and 20014
unique aggressively normalized (instruction, input) pairs. It preserves
10252 rows with non-empty inputs.
No semantic-quality filter, language classifier, code execution, or model-based
judgment was applied; this release intentionally does not rewrite source data.
Reproducibility and files
- Seed:
42. - Build script:
build.py. - Independent Hub verification script:
verify.py. - Machine-readable measurements:
stats.json. - Rejection evidence:
rejections.jsonl. - Validation report:
validation_report.json. - Source revision:
sahil2801/CodeAlpaca-20k@152bb5e9a29651266b018106053980070a0521a1. - HumanEval revision:
openai/openai_humaneval@7dce6050a7d6d172f3cc5c32aa97f52fa1a2e544. - MBPP revision:
google-research-datasets/mbpp@4bb6404fdc6cacfda99d4ac4205087b89d32030c.
| File | SHA-256 |
|---|---|
| Source Parquet as downloaded | 5a2fa0c510d42843292c583f357086abb59f95796e0f55727b97e449aa93bed9 |
data/train.parquet |
c00b9902c25983f60ebadb0a08905f42d44c5954ca0c8d5b4e0044e527adac5e |
data/test.parquet |
1200ef59fdc5854a2c571857c3695488754a783b6e17d778e392f05f60455864 |
rejections.jsonl |
bf88205147fb3074152c43849408aa9476f44441d8f91b99d213980b7d0c3ac7 |
Run python build.py to rebuild locally or python build.py --publish to rebuild
and upload. Publication reads HF_TOKEN from the environment or from the
profile .env; the token is never written to an artifact.
License and attribution
This dataset is CC BY-NC 4.0 — non-commercial use only.
The upstream repository sahil280114/codealpaca
ships two separate licence files, and they do not say the same thing:
| File | Covers | Licence |
|---|---|---|
LICENSE |
the training/generation code | Apache-2.0 |
DATA_LICENSE |
data/code_alpaca_20k.json, i.e. the data used here |
CC BY-NC 4.0 |
The Hugging Face mirror sahil2801/CodeAlpaca-20k
is tagged cc-by-4.0, which drops the NonCommercial clause present in the upstream
DATA_LICENSE. We verified both files directly rather than trusting the mirror's tag, and
this derivative follows the stricter upstream data licence: CC BY-NC 4.0.
Practical consequence: you may use, modify and redistribute this dataset for non-commercial purposes with attribution. Training a model on it for a commercial product is not covered. If you need a commercially usable code-instruction set, this is not the right dataset.
Attribution:
- Data: Sahil Chaudhary, Code Alpaca,
sahil280114/codealpaca,DATA_LICENSE(CC BY-NC 4.0). - Outputs were generated with OpenAI
text-davinci-003; OpenAI's terms of use apply to the generated content independently of this licence.
Limitations
The original outputs were generated with text-davinci-003; this release does
not independently validate their correctness, security, language, or
executability. Decontamination is limited to exact normalized equality and
lexical 13-gram overlap against the pinned HumanEval and MBPP test prompts; it
does not prove absence of semantic paraphrases. The test split measures this
source distribution and is not a replacement for external code benchmarks.
- Downloads last month
- 55