← 목록

Synth · CodeAlpaca일부

총 20,022개 · 페이지 388/668
🔀 랜덤
불러오는 중…

[output] | def delete_row(table, order_key): query = 'DELETE FROM {} WHERE order_key = ?'.format(table) try: cursor.execute(query, (order_key,)) cursor.commit() except: cursor.rollback() print('Error occurred while deleting order') [instruction] | Create a function to delete a specific row from a table named 'Orders'. [input] | Primary Key of the order: 1234

[output] | def count_word(words, target_word): counter = 0 for word in words: if word == target_word: counter += 1 return counter [instruction] | Write a code to count the number of occurrences of a given word in an array of strings. [input] | words = ['apple', 'banana', 'apple', 'kiwi', 'apple'] target_word = 'apple'

[output] | def swap_elements(array, index1, index2): temp = array[index1] array[index1] = array[index2] array[index2] = temp [instruction] | Create a code to swap two elements in a given array. [input] | array = [1, 4, 5, 8]

[output] | new_array = [item for item in given_array if item < 5] # [4, 1] [instruction] | Create a new array that is a copy of the given input array, consisting of all elements smaller than 5. [input] | [4, 8, 9, 7, 5, 1, 10]

[output] | def convert_to_base(num, base): """ Function to convert num to a given base """ converted_string = "" # Base Case if num < base: if num < 10: return str(num) else: return chr(num - 10 + ord('A')) rem = num % base if [instruction] | Create a recursive function that takes two parameters, a number and a base and returns the result as a string. [input] | 14, 16

[output] | """ Design a machine learning algorithm to classify the given dataset """ import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt #Prepare data data = pd.read_csv('path/to/dataset') #Preprocess data X = data.drop('label', axis=1) y = data['label'] #Split int [instruction] | Design a machine learning algorithm to classify the given dataset. [input] | Dataset of images of cats and dogs

[output] | public static double mean(int[] array) { double sum = 0; int length = array.length; // loop through each number and calculate the sum for (int num : array) sum += num; // calculate the mean and return it return sum/ length; } [instruction] | Design a solution using Java to calculate the mean of all the numbers in a given array. [input] | [4, 7, 11, 15, 18, 21]

[output] | rails new AppName cd AppName # Add devise for user auth rails g devise:install # Generate a model for the user rails g devise user username email password # Create a database and migrate rake db:create db:migrate # Add routes for the login & signup Rails.application.routes.draw do devise_for [instruction] | Create a Rails application with a user sign up with name, email and password. [input] |

[output] | <!DOCTYPE html> <html> <head> <title>My Webpage</title> <meta charset="utf-8"> <style> body { background-color: #f1f1f1; } .navbar { overflow: hidden; background-color: #444; } .navbar a { float: le [instruction] | Create a webpage using HTML and CSS that has a navigation bar with a logo, five links to different webpages, and a footer. [input] |

[output] | def combineName(firstName, lastName): """ A method that takes in two strings and combines them into a full name. Args: firstName (str): first name lastName (str): last name Returns: fullName (str): combined full name """ fullName = firstName + " " + lastNam [instruction] | Create a method called `combineName` that takes in two strings and combines them together into a full name. [input] | firstName = 'John' lastName = 'Smith'

[output] | def foo(a): """ A function that prints a value. Args: a (any): value to print Returns: nothing """ if isinstance(a, (int, float, str)): print(a) else: print("Error: must be a string, int, or float") if __name__ == '__main__': foo("hi") [instruction] | Fix the following code to prevent errors from crashing the program. [input] | def foo(a): print(a) foo("hi") foo(1)

[output] | A software bug is a mistake, error or an unexpected behavior or result in a computer program or system that causes it to produce an incorrect or unexpected result, or to behave in unintended ways. It is generally caused by errors in the source code or the semantic understanding of the code that is w [instruction] | Describe what a software bug is. [input] |

[output] | import re def extract_domain(url): """ A function to extract the domain from a URL using regex. Args: url (str): a URL. Returns: domain (str): the domain of the URL. """ regex = r"http[s]?://(www\.)?([^/]+)/.*" matches = re.search(regex, url) return matche [instruction] | Use regex to extract the domain from a URL. [input] | url = 'https://www.example.com/blog/post/1'

[output] | import random def get_random_element(list): """ A function to return a randomly selected element from a list. Args: list (list): a list Returns: element (int): a randomly selected element """ index = random.randint(0, len(list)-1) element = list[index] ret [instruction] | Create a function that returns a randomly selected element from a list. [input] | list = [1, 2, 3, 4, 5]

[output] | public class TwoDArray{ public static void print2DArray(int[][] arr){ for (int[] row : arr){ for (int element : row){ System.out.print(element+" "); } System.out.println(); } } public static void main(String[] args) [instruction] | Code a method in Java to print out the elements of a 2D array. [input] | [[1,2,3], [4,5,6], [7,8,9]]

[output] | public class SortExample{ public static void insertionSort(int[] arr){ int n = arr.length; for (int i=1; i<n; i++){ int key = arr[i]; int j = i - 1; while ( j>=0 && arr[j] > key){ arr[j+1] = arr[j]; j--; [instruction] | Code a method in Java to sort an array. [input] | [2, 9, 4, 6, 5, 1]

[output] | import random rand_string = '' for i in range(10): rand_string += random.choice(['a', 'b', 'c', 'd']) print(rand_string) [instruction] | Generate a random string of length 10 made up of characters ‘a’ to ‘d’. [input] |

[output] | def flatten_dict(d): flattened_dict = {} for key, val in d.items(): if type(val) is dict: # if val is a dict for k, v in val.items(): flattened_dict[key + "_" + k] = v else: flattened_dict[key] = val return flattened_dict if __name__ == '__main__': d = {"a": 1, "b": {"c": 2, "d" [instruction] | Code a function to flatten a dictionary. [input] | {"a": 1, "b": {"c": 2, "d": 3}}

[output] | def merge_sort(arr): if len(arr) >1: mid = len(arr) // 2 left_half = arr[:mid] right_half = arr[mid:] merge_sort(left_half) merge_sort(right_half) i = 0 j = 0 k = 0 while i < len(left_half) and j < len(right_half) [instruction] | Code an algorithm to implement merge sort [input] | [5, 2, 4, 6, 1, 7, 8]

[output] | my_list = [7, 9, 1, 3, 4] max = max(my_list) print(max) [instruction] | Find out the biggest number from the list [input] | [7, 9, 1, 3, 4]

[output] | def expand_list(strings): new_list = [] for string in strings: for character in string: new_list.append(character) return new_list [instruction] | Given a list of strings, write a Python function to expand each element into a set of characters. [input] | ['hello', 'world']

[output] | class Employee { constructor(name, age, salary) { this.name = name; this.age = age; this.salary = salary; } } [instruction] | Create a JavaScript class to represent an Employee object [input] |

[output] | public static void printReverse(int[] array) { for (int i = array.length - 1; i >= 0; i--) { System.out.println(array[i]); } } [instruction] | Create a Java method to print all elements in an array in reverse order. [input] |

[output] | SELECT * FROM table WHERE column = 'John'; [instruction] | Write a SQL query to find all rows in a table with a column value of 'John'. [input] |

[output] | def findDeepestNode(root): if root is None: return None queue = [] queue.append(root) while len(queue) > 0: res = queue[0] queue.pop() if res.left is not None: queue.append(res.left) if res.right is not None: queue.appen [instruction] | Given a tree, write a function that finds the deepest node in the tree. [input] |

[output] | def bubbleSort(arr): n = len(arr) for i in range(n): for j in range(0, n-i-1): if arr[j] > arr[j+1]: arr[j], arr[j+1] = arr[j+1], arr[j] return arr [instruction] | Design a Bubble Sort algorithm for a list of numbers. [input] |

[output] | def subsetsum(arr, target): arr.sort() n = len(arr) sum = 0 result = [] for i in range(n): if ( sum + arr[i] <= target): result.append(arr[i]) sum = sum + arr[i] return result [instruction] | Design a Greedy Algorithm to solve the sum-subset problem. [input] |

[output] | <!doctype html> <html> <head> <title>User Registration Form</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style type="text/css"> #form-div { background-color: #ffffff; padding: 10px 20px; border: #e0dfdf 1px solid; } #form-div h2 [instruction] | Create a PHP form to register a user. [input] |

[output] | [1, 2, 3, 4, 5, 6] [instruction] | Output the result of a line of code snippet. [input] | list_1 = [1, 2, 3] list_2 = [4, 5, 6] list_1 + list_2

[output] | x = 3 [instruction] | Transform the given code snippet into a different programming language. [input] | let x = 3

← → 방향키로 페이지 이동 · 숫자 입력 후 Enter로 점프