messages
listlengths
2
2
conversation_id
int64
0
20k
[ { "content": "Given a person's name and the current time, print the difference in time from the person's birthday.\nname = \"John\"\ntime = datetime.datetime(2021, 3, 25, 10, 0, 0)", "role": "user" }, { "content": "birthday = datetime.datetime.strptime(name + \" birthdate\", \"%Y-%m-%d\")\ntime_diff...
900
[ { "content": "Generate a random 2-digit number using JavaScript.", "role": "user" }, { "content": "Math.floor(Math.random() * 100);", "role": "assistant" } ]
901
[ { "content": "You are given an array of integers. Write a program to find the maximum number in this array.\n[10, 5, 11, 23, 9]", "role": "user" }, { "content": "def max_int(arr):\n max_val = arr[0]\n for i in range(1, len(arr)):\n if arr[i] > max_val:\n max_val = arr[i]\n return max_val\...
902
[ { "content": "Write a SQL query to retrieve all the rows from a table called \"customers\".", "role": "user" }, { "content": "SELECT * FROM customers;", "role": "assistant" } ]
903
[ { "content": "You are given two strings. Write a function that checks whether the two strings are an anagram or not.\n\"listen\", \"silent\"", "role": "user" }, { "content": "def is_anagram(str1, str2):\n str1 = str1.lower()\n str2 = str2.lower()\n if sorted(str1) == sorted(str2):\n return Tru...
904
[ { "content": "Write a function to multiply two numbers in Java.\n5, 8", "role": "user" }, { "content": "public static int multiply(int x, int y){\n return x * y;\n}\n\nSystem.out.println(multiply(5, 8));", "role": "assistant" } ]
905
[ { "content": "You are given a string of symbols. Write a program to remove all the symbols and get a valid text string.\n\"This , is an example string %\"", "role": "user" }, { "content": "def remove_symbols(string):\n text_string = ''\n for c in string:\n if c.isalpha() or c.isdigit():\n ...
906
[ { "content": "Compute the maximum product of two integers in an array.\n[-4, 2, -3, 6]", "role": "user" }, { "content": "def max_product(arr):\n max1 = max(arr)\n arr.remove(max1)\n max2 = max(arr)\n return max1 * max2\n\nprint(max_product([-4, 2, -3, 6]))", "role": "assistant" } ]
907
[ { "content": "Manipulate a given list to get a single string.\n[\"Hello\", \"World\", \"!\"]", "role": "user" }, { "content": "def create_string(arr):\n string = ''\n for elem in arr:\n string += elem\n return string\n\nprint(create_string(['Hello', 'World', '!']))", "role": "assistant" ...
908
[ { "content": "Rewrite the following for loop code using a list comprehension.\narr = [1,2,3,4,5]\nfor i in arr:\n arr[i] = arr[i] + 1", "role": "user" }, { "content": "arr = [x+1 for x in [1,2,3,4,5] ]\n\nprint(arr)", "role": "assistant" } ]
909
[ { "content": "You are given a list of numbers. Write a program to check if the given list is a palindrome or not.\n[1, 2, 3, 2, 1]", "role": "user" }, { "content": "def is_palindrome(arr):\n rev_arr = arr[::-1]\n if arr == rev_arr:\n return True\n else:\n return False\n\nprint(is_palindrome...
910
[ { "content": "Write a function in Python for printing a given 2D array.\narr = [[1,2,3], [4,5,6], [7,8,9]]", "role": "user" }, { "content": "def print_2D_array(arr):\n for row in arr:\n for element in row:\n print(element,end=\" \")\n print()\n\nprint_2D_array(arr)", "role": "assista...
911
[ { "content": "Identify the advantages of using deep learning models.", "role": "user" }, { "content": "The advantages of using deep learning models include: the ability to handle large and complex datasets; the ability to achieve better generalization performance; greater accuracy than traditional m...
912
[ { "content": "Create a function in Python for reversing a list.\nmy_list = [1,2,3,4,5]", "role": "user" }, { "content": "def reverse_list (my_list):\n return my_list[::-1]\n \nreverse_list(my_list)", "role": "assistant" } ]
913
[ { "content": "Describe the steps for implementing a convolutional neural network.", "role": "user" }, { "content": "The steps for implementing a convolutional neural network involve selecting the network architecture, preparing the dataset, defining the features, creating the layers and connections,...
914
[ { "content": "Develop an algorithm for sorting a given list in ascending order.\nmy_list = [5,1,4,2,8]", "role": "user" }, { "content": "def sort_list(my_list): \n for i in range(len(my_list)):\n for j in range(i+1, len(my_list)):\n if my_list[i] > my_list[j]: \n my_list[i], my_list[...
915
[ { "content": "Generate an array of 20 random numbers between 0 and 10 (inclusive).", "role": "user" }, { "content": "import random \n \narr = [] \nfor i in range(20): \n arr.append(random.randint(0, 10))\n \narr", "role": "assistant" } ]
916
[ { "content": "Write a code snippet for generating a unique identifier for a particular object.", "role": "user" }, { "content": "import uuid\n\ndef generate_id(object): \n return uuid.uuid4()", "role": "assistant" } ]
917
[ { "content": "Describe the process of web scraping.", "role": "user" }, { "content": "Web scraping is the process of extracting data from websites using automated software. It involves sending a request to the web server, processing the HTML, locating the relevant data, and saving it. The process us...
918
[ { "content": "Write a function in Python for calculating the area of a circle.", "role": "user" }, { "content": "def area_circle(r):\n return 3.14 * r**2", "role": "assistant" } ]
919
[ { "content": "Construct an if-else statement in Java for printing the square root of a given number.", "role": "user" }, { "content": "if (x >= 0) {\n System.out.println(Math.sqrt(x));\n} else {\nSystem.out.println(\"The number is negative\");\n}", "role": "assistant" } ]
920
[ { "content": "Write an API endpoint to get the average annual temperature of a given city.", "role": "user" }, { "content": "@app.route(\"/get_average_annual_temp/<city>\", methods=['GET'])\ndef get_average_annual_temp(city):\n # Get the average annual temperature of the given city\n temp = ge...
921
[ { "content": "Generate a string of 5 random characters from the characters A through Z.", "role": "user" }, { "content": "import random\n\ndef random_string():\n chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'\n random_string = ''.join(random.choice(chars) for i in range(5))\n return random_string\n\n...
922
[ { "content": "Create a React component that renders the provided state data in a table\nstate = {\n data: [\n { name: 'John', age: 20 },\n { name: 'Alice', age: 18 }\n ]\n}", "role": "user" }, { "content": "import React from 'react';\n\nclass Table extends React.Component {\n render() {\n ...
923
[ { "content": "Create a CSS animation to apply an interesting effect to a given element.", "role": "user" }, { "content": "element {\n -webkit-animation: myAnimation 2s ease-in forwards; \n animation: myAnimation 2s ease-in forwards;\n}\n\n@-webkit-keyframes myAnimation {\n from {\n transfor...
924
[ { "content": "Build a flask server to handle a GET request to the route '/test'.", "role": "user" }, { "content": "from flask import Flask, request\n\napp = Flask(__name__)\n\n@app.route('/test', methods=['GET'])\ndef test():\n return \"This is a test\"\n\nif __name__ == '__main__':\n app.run(...
925
[ { "content": "Train a sentiment classification model on the given data.\nTraining Data:\n\nI love this new phone! Positive\nThis phone is terrible! Negative", "role": "user" }, { "content": "import nltk \nfrom nltk.corpus import stopwords\nfrom nltk.tokenize import word_tokenize\n\n# Preprocess da...
926
[ { "content": "Create a parameterized SQL query to get all records from a table where the given field has a value greater than the given input.\nFields: age\nInput: 20", "role": "user" }, { "content": "SELECT * FROM table_name WHERE age > 20;", "role": "assistant" } ]
927
[ { "content": "Given a Python list, write the code to flatten it\nl1=[1,2,3,[4,[5,6]]]", "role": "user" }, { "content": "def flatten(nums):\n flattened_list = []\n for elem in nums:\n if type(elem) == list:\n flattened_list.extend(flatten(elem))\n else:\n fla...
928
[ { "content": "Write a function in Python that takes two parameters and returns a list containing those two numbers", "role": "user" }, { "content": "def make_list(a, b):\n return [a, b]", "role": "assistant" } ]
929
[ { "content": "Add a new element to the end of a list.\nmylist=[2,5,7]", "role": "user" }, { "content": "mylist.append(9)", "role": "assistant" } ]
930
[ { "content": "Write a function that prints a message saying 'Hello world!'", "role": "user" }, { "content": "def say_hello():\n\tprint(\"Hello world!\")", "role": "assistant" } ]
931
[ { "content": "Write a sorting algorithm that sorts an array using a bubble sort.\nnums=[3,4,1,2,9,6]", "role": "user" }, { "content": "def bubble_sort(nums):\n for i in range(len(nums)):\n for j in range(i+1, len(nums)):\n if nums[i] > nums[j]:\n nums[i], nums[j] ...
932
[ { "content": "Create a list containing a given number of random numbers.", "role": "user" }, { "content": "import random\n\ndef random_list(length):\n\trand_list = []\n\tfor i in range(length):\n\t\trand_list.append(random.randint(0,100))\n\treturn rand_list", "role": "assistant" } ]
933
[ { "content": "Using the existing code as guidance, add a 2nd player and 2nd input field to the game.\nplayername1=input(\"What is your name? \")\nplayer_score1=0\n\nif turn==1:\n\tplayer_score1+=1\n\nprint(\"It is now \" + playername1 + \" turn. You have \" + str(player_score1) + \" points\")", "role": "use...
934
[ { "content": "Using the existing code as a guide, construct a function to validate user input.\nusername=input(\"Enter your username: \")\npassword=input(\"Enter your password: \")", "role": "user" }, { "content": "def validate_input(username, password):\n\tif len(username) < 5 or len(username) > 80...
935
[ { "content": "Create a function to generate a random integer between two given numbers.", "role": "user" }, { "content": "import random\ndef rand_int(low, high):\n\treturn random.randint(low,high)", "role": "assistant" } ]
936
[ { "content": "Analyze the following text and produce the sentiment score.\nText: I am extremely disappointed with the customer service I received.", "role": "user" }, { "content": "Sentiment score: -2.", "role": "assistant" } ]
937
[ { "content": "Create a function in Python that returns all permutations of a string.", "role": "user" }, { "content": "def get_all_permutations(string):\n \n if len(string) == 1:\n return [string]\n \n permutations = []\n for index, char in enumerate(string):\n slice_string = string[:index...
938
[ { "content": "Given a character sequence, find the longest palindromic substring.\nsequence: madam", "role": "user" }, { "content": "madam", "role": "assistant" } ]
939
[ { "content": "Debug the following code to make it compile properly.\ndef addNumbers(num1, num2)\n return num1 + num2", "role": "user" }, { "content": "def addNumbers(num1, num2):\n return num1 + num2", "role": "assistant" } ]
940
[ { "content": "Given a positive integer, find the sum of its digits.", "role": "user" }, { "content": "def findSum(num): \n res = 0\n num = str(num)\n for i in range(0, len(num)): \n res = res + int(num[i]) \n \n return res", "role": "assistant" } ]
941
[ { "content": "Write a loop in React that renders a list of numbers from 1 - 10.", "role": "user" }, { "content": "render() {\n const numbers = [1,2,3,4,5,6,7,8,9,10];\n return (\n <ul>\n {numbers.map(number => <li>{number}</li>)}\n </ul>\n );\n}", "role": "assistant" } ]
942
[ { "content": "Find the greatest common divisor of these two numbers.\n9 and 15", "role": "user" }, { "content": "3", "role": "assistant" } ]
943
[ { "content": "Explain the concept of Generative Adversarial Networks (GANs).", "role": "user" }, { "content": "Generative Adversarial Networks (GANs) are a type of deep neural network that are composed of two sub-networks; a generative network and a discriminative network. The generative network pro...
944
[ { "content": "Write a jQuery code snippet to retrieve the value of an input field with an id of \"name\".", "role": "user" }, { "content": "$(\"#name\").val();", "role": "assistant" } ]
945
[ { "content": "Implement the following algorithm in Java.\n// Bubble sort algorithm \nfor i in 0 to n-1 \n for j in 0 to n-i-1 \n if array[j] > array[j+1] \n swap array[j] and array[j+1]", "role": "user" }, { "content": "public void bubbleSort(int[] arr){\n for (int i = 0; i < arr.length - ...
946
[ { "content": "Explain the term \"backtracking\".", "role": "user" }, { "content": "Backtracking is a general algorithm for finding all (or some) solutions to some computational problems, that incrementally builds candidates to the solutions and abandons each partial candidate c (\"backtracks\") as s...
947
[ { "content": "Create an array of strings, of size 5, by taking the string input from the user.\n\"hello\", \"world\", \"this\", \"is\", \"a\"", "role": "user" }, { "content": "arr = [\"hello\", \"world\", \"this\", \"is\", \"a\"]", "role": "assistant" } ]
948
[ { "content": "Write a JavaScript function to convert an array of strings to a comma-separated string.\narr = [\"this\", \"is\", \"a\", \"test\"]", "role": "user" }, { "content": "//Function to convert an array of strings to a comma-separated string\nfunction arr_to_csv(arr) {\n return arr.join(\"...
949
[ { "content": "Write code for displaying the Fibinacci sequence 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: \n...
950
[ { "content": "Create an array of size n filled with the string \"hello\".", "role": "user" }, { "content": "def fillWithHello(n):\n arr = [] \n for i in range(0, n): \n arr.append(\"hello\") \n return arr", "role": "assistant" } ]
951
[ { "content": "Re-write the following function to use list comprehension.\ndef negative_list(numbers):\n negative = []\n for num in numbers:\n if num < 0:\n negative.append(num)\n return negative", "role": "user" }, { "content": "def negative_list(numbers):\n return [num...
952
[ { "content": "Convert the following function to a lambda expression\ndef power_of_two(x):\n return x ** 2", "role": "user" }, { "content": "power_of_two = lambda x : x ** 2", "role": "assistant" } ]
953
[ { "content": "Convert the following nested for loop into a single line list comprehension.\na = [1, 2, 3, 4]\nb = [5, 6, 7, 8]\n\nresult = []\nfor i in a:\n for j in b:\n result.append((i, j))", "role": "user" }, { "content": "result = [(i,j) for i in a for j in b]", "role": "assistant...
954
[ { "content": "Pre-process the following dataset and convert it into a tabular format using Pandas.\ndata = [{\"name\": \"john\", \"age\": 20, \"location\": \"New York\"},\n {\"name\": \"sarah\", \"age\": 30, \"location\": \"Los Angeles\"}]", "role": "user" }, { "content": "import pandas as pd...
955
[ { "content": "Find all substrings from a given string.", "role": "user" }, { "content": "def find_substring(str):\n substrings = []\n for length in range(1, len(str)+1):\n for start in range(len(str)- length + 1):\n substrings.append(str[start:start+length])\n return subst...
956
[ { "content": "Softmax a list of numbers and then sum the output.\n[1, 2, 3]", "role": "user" }, { "content": "def softmax(arr): \n a = np.exp(arr)\n return a / np.sum(a) \ndef sum_softmax(arr): \n return np.sum(softmax(arr))", "role": "assistant" } ]
957
[ { "content": "Toast a Python function to swap the values of two given variables.\na = 10, b= 20", "role": "user" }, { "content": "def swap(a, b): \n a, b = b, a \n return (a,b)", "role": "assistant" } ]
958
[ { "content": "Create a function to calculate the Levenshtein distance between two strings\nstr1 = \"geeks\", str2 = \"geek\"", "role": "user" }, { "content": "def lev_dist(str1, str2):\n if len(str1) < len(str2):\n return lev_dist(str2, str1)\n \n if len(str2) == 0:\n return l...
959
[ { "content": "Create an algorithm to sort a given array in ascending order using Bubble sort.", "role": "user" }, { "content": "def bubble_sort(arr): \n # length of the array \n n = len(arr) \n \n # Traverse through all array elements \n for i in range(n-1): \n \n # Last i elem...
960
[ { "content": "Create a program to check if two given strings are a rotation of each other.\nstring1 = \"abcd\", string2= \"cdab\"", "role": "user" }, { "content": "def isRotation(s1, s2): \n if len(s1) != len(s2): \n return False\n \n temp = s1 + s1 \n return (temp.count(s2) > 0)"...
961
[ { "content": "Deploy a Docker container to Heroku.\nHeroku account details", "role": "user" }, { "content": "Log in to Heroku using the account details provided.\nUse the command \"heroku container:push web -a [app-name]\" to deploy the container to Heroku. This command will build and push the Docke...
962
[ { "content": "Predict the sentiment of a given sentence.\nThis movie was fairly dull.", "role": "user" }, { "content": "The sentiment of the statement is negative.", "role": "assistant" } ]
963
[ { "content": "Create a neural network in Python to recognize handwriting.\nMNIST hand-written digit dataset", "role": "user" }, { "content": "The code to create a neural network in Python to recognize handwriting should consist of several parts. These parts include importing the MNIST dataset, prepr...
964
[ { "content": "Design an HTML page with a table of products and their prices.\nTable with 5 products and their prices", "role": "user" }, { "content": "<html>\n <head>\n <title>Product Prices</title>\n </head>\n <body>\n <h1>Product Prices</h1>\n <table>\n <tr>\n <th>Product Name</th><th>Pric...
965
[ { "content": "Write a CSS selector to select all paragraph elements with a class of \"highlight\".", "role": "user" }, { "content": "p.highlight {\n /* CSS styles */\n}", "role": "assistant" } ]
966
[ { "content": "Determine the average of 3 numbers.\n30, 20, 60", "role": "user" }, { "content": "The average of the 3 numbers is 36.", "role": "assistant" } ]
967
[ { "content": "Develop a machine learning algorithm to predict stock prices.\nHistorical stock prices", "role": "user" }, { "content": "The algorithm should include parts like data preprocessing, feature extraction, selecting the right model, hyperparameter optimization and evaluation.", "role": ...
968
[ { "content": "Identify the most frequent word in a given sentence.\nThis is a beautiful summer day", "role": "user" }, { "content": "The most frequent word in the sentence is \"a\".", "role": "assistant" } ]
969
[ { "content": "Write a JavaScript function to generate a random whole number.", "role": "user" }, { "content": "function getRandomNumber() {\n return Math.floor(Math.random() * 100);\n}", "role": "assistant" } ]
970
[ { "content": "Create a PHP page to add two numbers.", "role": "user" }, { "content": "<html>\n <head>\n <title>Add two numbers</title>\n </head>\n <body>\n <?php\n if (isset($_POST['add'])) {\n $num1 = $_POST['num1'];\n $num2 = $_POST['num2'];\n $sum = $num1 + $num2;\n ?>\n <p>The sum...
971
[ { "content": "Write pseudo code for finding the maximum element in an array.", "role": "user" }, { "content": "START\nSET max_element to 0\nLOOP through array\n IF current element is greater than max_element\n SET max_element to current element\nEND LOOP\nPRINT maximum element\nEND", "role": "as...
972
[ { "content": "How would you modify the following code to print the square of each number in the given list?\nnums = [1, 2, 3, 4]", "role": "user" }, { "content": "nums = [1, 2, 3, 4]\n\nfor i in range(len(nums)):\n nums[i] = nums[i] * nums[i]\n\nprint(nums) # [1, 4, 9, 16]", "role": "assistan...
973
[ { "content": "What does the following code do?\ndef division(num1, num2):\n return num1 / num2", "role": "user" }, { "content": "The code defines a function called division which takes two numbers as arguments and returns the result of dividing the first number by the second number.", "role":...
974
[ { "content": "Write a function that takes a string of numbers separated by commas and returns the sum of all the numbers.\n\"1,2,3,4\"", "role": "user" }, { "content": "def sum_numbers(nums): \n nums = nums.split(',')\n total = 0\n \n # Traverse the string and add all elements \n # of i...
975
[ { "content": "Create a function that takes the string of the current time and returns the time in minutes.\n\"12:30PM\"", "role": "user" }, { "content": "def convert_to_minutes(time): \n # Split the time into hours and minutes \n h, m = map(int, time.split(':'))\n\n # Add 12 to the hours if...
976
[ { "content": "Create a function that takes two strings and returns a new string containing the first three characters of each string combined.\n\"Hello\"\n\"World\"", "role": "user" }, { "content": "def combine_first_three(string1, string2): \n # Get the first three characters of each string \n ...
977
[ { "content": "How would you modify the following code to make it more efficient?\ndef find_word(word, text):\n if word in text:\n return \"Word found\"\n else:\n return \"Word not found\"", "role": "user" }, { "content": "def find_word(word, text):\n # Use the 'in' operator to...
978
[ { "content": "Create a function that takes a list of numbers and returns the index of the largest number.\n[2, 5, 12, 3, 4]", "role": "user" }, { "content": "def find_largest_number(nums): \n # Initialize the index of the largest number.\n largest_index = 0\n\n # Loop through the list of nu...
979
[ { "content": "Write a function that takes a sentence and returns the string with all occurrences of the longest word removed.\n\"This is a very long sentence\"", "role": "user" }, { "content": "def remove_longest_word(sentence): \n # Split the sentence into words \n words = sentence.split(' ')...
980
[ { "content": "Write a database query to retrieve the names of all authors.", "role": "user" }, { "content": "SELECT name \nFROM authors;", "role": "assistant" } ]
981
[ { "content": "Build a regular expression to check if a string only contains numbers.", "role": "user" }, { "content": "^[0-9]+$", "role": "assistant" } ]
982
[ { "content": "You are given a list of items. Output a list of items and their respective frequencies.\n[1,2,2,4,5,2,3,4,5,6]", "role": "user" }, { "content": "1: 1\n2: 3\n3: 1\n4: 2\n5: 2\n6: 1", "role": "assistant" } ]
983
[ { "content": "Construct a for loop to show the multiplication table of 3.", "role": "user" }, { "content": "for(i=1;i<=10;i++) {\n console.log(3 + \" x \" + i + \" = \" + (3 * i));\n}", "role": "assistant" } ]
984
[ { "content": "Create a basic neural network model to distinguish between cats and dogs.", "role": "user" }, { "content": "Model Building Code:\nmodel = Sequential([\n Conv2D(32, (3,3), activation='relu', input_shape=(150, 150, 3)),\n MaxPooling2D(2,2),\n Conv2D(64, (3,3), activation='relu')...
985
[ { "content": "Read the given code block and debug it.\ndef main():\n print(\"Hey I'm here\")\n if n == 0: \n print(\"Hey I'm there\")\nmain()", "role": "user" }, { "content": "Error: n is not defined.\n\nThe given code is trying to use the variable n, which is not declared. To fix this, it should b...
986
[ { "content": "Find the closest decimal approximation of 0.875.", "role": "user" }, { "content": "0.88", "role": "assistant" } ]
987
[ { "content": "Write a Java code to calculate the maximum value in an array.", "role": "user" }, { "content": "public static int getMax(int[] array) {\n int max = array[0];\n for (int i=1; i < array.length; i++) {\n if (array[i] > max) {\n max = array[i];\n }\n }\n return max;\n}", ...
988
[ { "content": "Construct a loop to output all the elements from a list.\n['a', 'b', 'c', 'd']", "role": "user" }, { "content": "for i in range(len(arr)):\n print(arr[i])", "role": "assistant" } ]
989
[ { "content": "Create an algorithm to detect if a string is a palindrome or not.", "role": "user" }, { "content": "def isPalindrome(s): \n reversedString = s[::-1] \n \n if (s == reversedString): \n return True\n return False", "role": "assistant" } ]
990
[ { "content": "Provide a function to find the length of a string.", "role": "user" }, { "content": "def length(s):\n i = 0\n for ch in s:\n i += 1\n return i", "role": "assistant" } ]
991
[ { "content": "Modify the following code to get the desired output.\nfor i in range(1, 7):\n for j in range(1, i):\n print(j)", "role": "user" }, { "content": "for i in range(1, 7):\n for j in range(1, i+1):\n print(j, end=' ')\n print()", "role": "assistant" } ]
992
[ { "content": "Write a function that takes in two strings as input and outputs True if they are anagrams, False otherwise.\ns1 = “silent”\ns2 = “listen”", "role": "user" }, { "content": "def anagrams(s1, s2):\n if len(s1) != len(s2):\n return False\n s1_arr = list(s1)\n s2_arr = list(...
993
[ { "content": "Generate a sentence using the given array of words:\narr = ['This', 'is', 'a', 'sentence']", "role": "user" }, { "content": "This is a sentence.", "role": "assistant" } ]
994
[ { "content": "Swap the contents of two variables.\na = 10\nb = 15", "role": "user" }, { "content": "a, b = b, a", "role": "assistant" } ]
995
[ { "content": "Generate a function which will validate a phone number using regular expression.", "role": "user" }, { "content": "def validate_phone(phone_number):\n regex = '^\\+?(\\d[\\d-. ]+)?(\\([\\d-. ]+\\))?[\\d-. ]+\\d$'\n if re.match(regex, phone_number):\n return True\n retur...
996
[ { "content": "Modify the given code to multiply two n x n matrices.\ndef multiply(m1, m2, n):\n result = [[0 for x in range(n)] for y in range(n)]\n for i in range(n):\n for j in range(n): \n result[i][j] = 0", "role": "user" }, { "content": "def multiply(m1, m2, n):\n res...
997
[ { "content": "Write a function to return the index of an item in an array.\narr = [1, 2, 3, 4, 5]\nx = 4", "role": "user" }, { "content": "def index(arr, x):\n for i in range(len(arr)):\n if arr[i] == x:\n return i\n return -1", "role": "assistant" } ]
998
[ { "content": "Generate a list that has the all even numbers between 1 and 50, inclusive.", "role": "user" }, { "content": "even_nums_list = [x for x in range(1,51) if x % 2 == 0]", "role": "assistant" } ]
999