← 목록

Synth · CodeAlpaca일부

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

[output] | def reverse_list(list): start = 0 end = len(list) - 1 while start < end: list[start], list[end] = list[end], list[start] start += 1 end -= 1 return list [instruction] | Create code that will reverse the order of elements in this list. [input] | list = [1, 2, 3, 4]

[output] | def longest_increasing_subarray(arr): max_length = 1 curr_length = 1 for i in range(1, len(arr)): if arr[i] > arr[i - 1]: curr_length += 1 else: if curr_length > max_length: max_length = curr_length curr_length = 1 [instruction] | Create a function that will find the maximum length of increasing subarray in a list [input] | list = [2, 3, 3, 1, 4, 5, 8, 4]

[output] | def longest_consecutive_character(str): # Store character, length of longest permutation, and current length max_char = str[0] max_length = 1 cur_length = 1 # Iterate over the string for i in range(1, len(str)): # If the characters are the same if str[i] == [instruction] | Create code that, given a string, returns the longest permutation of the same character [input] | str = "abcccdef"

[output] | def longest_subarray(arr): # Stores index of previos zero prev_zero = -1 # Stores index and length of longest subarray with equal 0 and 1 max_len = 0 start_index = 0 # Traverse the given array for i in range(len(arr)): # Update previous zero i [instruction] | Create code to find the longest subarray with equal number of 0's and 1's [input] | list = [0, 0, 1, 0, 1, 0, 0, 1]

[output] | def are_identical(Tree1, Tree2): # Both trees are empty if Tree1==None and Tree2==None: return True # If only one of them is empty if (Tree1==None or Tree2==None): return False # Both non-empty, compare the data and # recur for left and right sub-t [instruction] | Create code that given two binary search trees, determine if they are identical [input] | Two Binary Search Trees: Tree1 and Tree2

[output] | def add_numbers(list1, list2): start = result = ListNode(0) carry = 0 # Iterate both Lists until the end while list1 or list2 or carry: val1 = 0 val2 = 0 # If l1 is not None, add data if list1: val1 = list1.data list1 = l [instruction] | Create a function that will add two numbers (represented as linked lists) [input] | Linked lists: list1 = [2, 4, 3] and list2 = [5, 6, 4]

[output] | def reverse_stack(stack): if len(stack) == 0: return # Pop the first element from the stack temp = stack.pop() # Call the reverse_stack method on the remaining elements reverse_stack(stack) # Push the poped element to the bottom of the stack insert_at_bottom(stack, temp) retur [instruction] | Create code that given a stack (i.e., a sequence of objects), returns the reversed stack [input] | stack = [1, 2, 3, 4]

[output] | class Queue: def __init__(self): self.items = [] def enqueue(self, item): self.items.insert(0, item) def dequeue(self): if not self.is_empty(): return self.items.pop() def is_empty(self): return len(self.items) == 0 [instruction] | Create a function to build a queue (i.e., a sequence of objects) [input] |

[output] | import requests url = 'http://example.com/api/v1/data' response = requests.get(url) data = response.json() [instruction] | Write a code snippet to store the output of an API call into a variable. [input] | url = 'http://example.com/api/v1/data'

[output] | import tkinter # create the main window root = Tk() # create the user interface root.title("Order System") root.geometry("400x200") # create widgets Label(root, text = 'Name:').grid(row = 0, column = 0, padx = 10, pady = 10) Entry(root).grid(row = 0, column = 1, columnspan = 2, padx = [instruction] | Create a user interface for a customer order system. [input] |

[output] | resource "azurerm_resource_group" "example" { name = "example-resources" location = "westus2" } resource "azurerm_virtual_machine" "example" { name = "example-vm" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_ [instruction] | Create a virtual machine using Terraform. [input] |

[output] | import requests def get_latest_python_version(): url = 'https://www.python.org/ftp/python/' response = requests.get(url) if response.status_code == 200: html = response.text start_index = html.find('<a href="') if start_index != -1: end_ [instruction] | Make a REST API call to get the latest version of Python. [input] |

[output] | <html> <head> <title>Hello World</title> </head> <body> <h1>Hello World!</h1> </body> </html> [instruction] | Create a web page with a simple "Hello World" message. [input] |

[output] | import collections def get_most_used_words(string): # Tokenize the string words = string.split() # Calculate frequency of each word freq = {} for word in words: if word in freq: freq[word] += 1 else: freq[word] = 1 # Sort the words in de [instruction] | Get the top ten most used words within a string. [input] |

[output] | num1 = 5 num2 = 6 if num1 > num2: print("The number is greater than 5.") else: print("Success! The number is less than or equal to 5.") [instruction] | Edit the following code snippet to add if/else logic for printing a success message. [input] | num1 = 5 num2 = 6 if num1 > num2: print("The number is greater than 5.")

[output] | ^ha\w+ [instruction] | Generate a regex expression to find all words starting with "ha" [input] |

[output] | SELECT * FROM clients WHERE email = 'test@example.com'; [instruction] | Construct a SQL query to find all clients with a given email address. [input] | The email address is "test@example.com"

[output] | let reverseString = (str) => str.split('').reverse().join(''); [instruction] | Construct an expression in javascript to reverse a string. [input] |

[output] | <!DOCTYPE html> <html> <head> <title>Simple Form</title> </head> <body> <form> Name: <input type="text" name="name"/><br><br> Email: <input type="email" name="email"/><br><br> <input type="submit" value="Submit"/> </f [instruction] | Make a HTML5 webpage with a simple form. [input] |

[output] | <!DOCTYPE html> <html> <head> <title>Adding Form</title> </head> <body> <form action="" method="post"> <input type="number" name="a"> <input type="number" name="b"> <input type="submit" value="Submit" /> </form> <script> document.querySelector('form').onsubmit = function(event [instruction] | Create a HTML page with a form that takes in two numbers as input and adds them together when the form is submitted. [input] |

[output] | const express = require('express'); const app = express(); app.get('/time', (req, res) => { const date = new Date(); const time = { hour: date.getHours(), minutes: date.getMinutes(), seconds: date.getSeconds() } res.json(time) }); app.listen(6000); [instruction] | Create an API endpoint in NodeJS that returns a JSON object containing the current time. [input] |

[output] | SELECT * FROM products ORDER BY sale_price desc LIMIT 5; [instruction] | Write an SQL query to fetch the top 5 products with the highest sale prices from a table named 'products'. [input] |

[output] | SELECT user_id, username, age, subscriptions FROM users WHERE age < 24 AND subscriptions >= 10 [instruction] | Construct a valid and optimized MySQL query to get the user details of all users who are younger than 24 and have subscribed more than 10 times. [input] |

[output] | def gradient_descent(cost_function, theta, eta, tolerance): cost = cost_function(theta) diff = tolerance + 1 while diff > tolerance: theta_updated = theta for i in range(len(theta)): theta[i] = theta[i] - eta * cost_function.gradient_wrt_theta(theta, i) [instruction] | Generate a gradient descent algorithm to optimize a cost function. [input] |

[output] | def preOrder(root): if root: print(root.data) preOrder(root.left) preOrder(root.right) [instruction] | Construct a pre-order traversal code to traverse a binary tree. [input] |

[output] | final_list = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5] [instruction] | Create an array of length 10 from a given list of values. [input] | given_list = [1, 2, 3, 4, 5]

[output] | def merge_sort(arr): if len(arr) > 1: mid = len(arr) // 2 L = arr[:mid] R = arr[mid:] #calling merge sort function on left and right arrays merge_sort(L) merge_sort(R) i = j = k = 0 # Copying data to temp arrays L[] and R[] [instruction] | Implement the merge sort algorithm to sort a given array ascending. [input] | given_array = [7,9,3,8,1]

[output] | # importing the modules import http.server import socketserver # defining the port number port = 8080 # the web page index_html = """<!DOCTYPE html> <html> <head> <title>My Website</title> </head> <body> <h1> Welcome to my website!</h1> <p>Here you will find useful information about me and my work [instruction] | Write a code to create a web server for a given web page. [input] |

[output] | uniques = {} for item in given_list: if item not in uniques: uniques[item] = 1 else: uniques[item] += 1 # result: {1: 3, 2: 2, 3: 1} [instruction] | Compact a given list into a dictionary with unique items as keys. [input] | given_list = [1,1,1,2,2,3]

[output] | def my_function(x):     y = x * 2     return x + y result = my_function(2) print("The result is:", result) [instruction] | Edit the code to make sure the program prints the correct output. [input] | def my_function(x):     y = x * 2     return x + y result = my_function(2) print(result)

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