← 목록

Synth · CodeAlpaca일부

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

[output] | SELECT * FROM books ORDER BY rating DESC LIMIT 10; [instruction] | Write a SQL query to get the top 10 books by rating. [input] |

[output] | def print_odd_numbers(): for i in range(1, 11): if i % 2 != 0: print(i) print_odd_numbers() [instruction] | Design a function that uses a for loop to print all odd numbers from 1 to 10. [input] |

[output] | def word_count(sentence): words = sentence.split(' ') return len(words) print(word_count('This is a sample sentence.')) [instruction] | Design a program in Python that will count the words in a sentence. [input] | This is a sample sentence.

[output] | import pandas as pd data = [{"animal": "cat"}, {"animal": "dog"}, {"animal": "fish"}] df = pd.DataFrame(data) print(df) [instruction] | How can you create a Pandas DataFrame using a given list of dictionaries? [input] | [{"animal": "cat"}, {"animal": "dog"}, {"animal": "fish"}]

[output] | let arr = [1, 2, 3, 4, 5]; arr.reverse(); console.log(arr); [instruction] | Edit the given code to reverse a given array in JavaScript. [input] | let arr = [1, 2, 3, 4, 5];

[output] | def fibonacci(n): if n <= 1: return n else: return(fibonacci(n-1) + fibonacci(n-2)) print(fibonacci(10)) [instruction] | How would you use Recursion to solve the Fibonacci Sequence in Python? [input] |

[output] | function reversedAddition(reverseOrder1, reverseOrder2) { let firstNum = parseInt(reverseOrder1.toString().split('').reverse().join('')); let secondNum = parseInt(reverseOrder2.toString().split('').reverse().join('')); let answer = firstNum + secondNum; return answer; } console.l [instruction] | Construct a function that adds two numbers written in reverse order in JavaScript. [input] | 893 342

[output] | let array1 = [1, 2, 3]; let array2 = [4, 5, 6]; let el = array1.pop(); array2.push(el); console.log(array2); [instruction] | How can you move an element from one array to another in JavaScript? [input] | let array1 = [1, 2, 3]; let array2 = [4, 5, 6];

[output] | def get_num_elements(data): count = 0 for item in data: count += 1 return count data = [{"name":"John"},{"name":"Bob"},{"name":"Alice"}] print(get_num_elements(data)) [instruction] | Design a function to get the number of elements in a JSON array in Python. [input] | [{"name":"John"},{"name":"Bob"},{"name":"Alice"}]

[output] | #include <iostream> #include <string> using namespace std; int main() { string my_string = "Count characters in this string."; int count = 0; for (char c : my_string) count++; cout << "Number of characters in the string : " << count; return 0; } [instruction] | What is the most efficient way to count the number of characters in a string in C++? [input] |

[output] | function removeSpecialChars(str) { return str.replace(/[^\w\s]/gi, ''); } console.log(removeSpecialChars('$sample!%string!*')); [instruction] | Construct a function that will remove all special characters in a given string in JavaScript. [input] | $sample!%string!*

[output] | import numpy as np import matplotlib.pyplot as plt # generate dataset x = np.random.rand(100, 1) y = 4 + 3 * x + np.random.rand(100, 1) # linear regression x_b = np.c_[np.ones((100, 1)), x] theta_best = np.linalg.inv(x_b.T.dot(x_b)).dot(x_b.T).dot(y) # prediction x_new = np.array([[0], [1]]) x_ne [instruction] | Develop a program in Python to implement a Simple Linear Regression model. [input] |

[output] | SELECT * FROM Table WHERE ModifiedTime BETWEEN '<start-time>' AND '<end-time>'; [instruction] | Develop a SQL query to find all the records that have modified within a given time range. [input] |

[output] | async function handleData(data, cb) { if (data.type === 'A') { const filteredData = data.filter(x => x.name === 'hello') const processedData = filteredData.map(x => x.value) const result = processedData.length cb(result) } } [instruction] | Make the existing JavaScript function asynchronous. [input] | function handleData(data, cb) { if (data.type === 'A') { const filteredData = data.filter(x => x.name === 'hello') const processedData = filteredData.map(x => x.value) const result = processedData.length cb(result) }

[output] | def swap(List): temp = List[0] List[0] = List[3] List[3] = temp return List List = [10, 20, 30, 40] print(swap(List)) [instruction] | Write a function to swap the entries in a list. [input] | [10, 20, 30, 40]

[output] | try: def read_file(file): with open(file) as f: for line in f: print(line) except IOError: print("Error: Could not read file") finally: print("Closing file") f.close() [instruction] | Change the following program to use a try/except/finally block to handle errors. [input] | def read_file(file): with open(file) as f: for line in f: print(line)

[output] | A dictionary or set can be used to store a customer’s name, address, and phone number. The customer's name would be used as the key and the associated customer information such as address and phone number would be stored as the value. [instruction] | What data structure should be used to store a customer’s name, address, and phone number? [input] |

[output] | def second_highest(List): List.sort() return List[-2] List = [10, 20, 30, 40] print(second_highest(List)) [instruction] | Suggest a function to find the second highest element in a list. [input] | [10, 20, 30, 40]

[output] | A dictionary of dictionaries or a linked list could be used to represent a sparse matrix with thousands of columns and rows. The outer dictionary would serve as an index table to refer to each row of the matrix while the inner dictionary contains key-value pairs of column index and the corresponding [instruction] | What data structure would be suitable to represent a sparse matrix with thousands of columns and rows? [input] |

[output] | A radix sort would be an appropriate sorting algorithm for an array that contains both duplicates and unique elements. Radix sorts start by sorting the array based on the least significant digit, and then sort based on the next digit, and so on. [instruction] | Suggest a sorting algorithm for an array that contains both duplicates and unique elements. [input] | [8, 4, 3, 5, 9, 8, 10]

[output] | selected_rows = df[df.name.notnull()] [instruction] | Select all rows in a pandas dataframe where at least one value exists in the column named ‘name’. [input] |

[output] | SELECT DISTINCT * FROM students; [instruction] | Write an SQL query to pick distinct elements from a table named 'students'. [input] |

[output] | def longest_substring(string): curr_len = 1 max_len = 1 prev_index = 0 n = len(string) visited = [-1] * 256 visited[ord(string[0])] = 0 for i in range(1,n): prev_index = visited[ord(string[i])] if prev_index == -1 or (i - curr_len > prev_index): [instruction] | Create a function that returns the longest substring of the string given. [input] | string = "Hello world!"

[output] | def clone_set(my_set): new_set = set() for item in my_set: new_set.add(item) return new_set [instruction] | Write a Python program to create a copy of a given set. [input] | my_set = {1, 2, 3, 4, 5}

[output] | def search(arr, key): for i in range(len(arr)): if arr[i] == key: return i return -1 [instruction] | Create a function to search the given list to find a key value and return its position. [input] | arr = ['a', 'b', 'c', 'd'] key = 'a'

[output] | def convert_to_string(integers): string_list = [] for item in integers: string_list.append(str(item)) return string_list [instruction] | Given a list of integers, write a program to convert it into a list of strings. [input] | integers = [1, 2, 3, 4]

[output] | def calculate_area(length, width): area = length * width return "The area is " + str(area) [instruction] | Edit the Python code snippet to remove the syntax error. [input] | def calculate_area(length, width): area = length * width return “The area is” + area

[output] | import random def sample_list(list): list_copy = list.copy() sampled_list = [] while list_copy: element = random.choice(list_copy) sampled_list.append(element) list_copy.remove(element) return sampled_list [instruction] | Write a Python program to randomly sample a list without replacement. [input] | list = [30, 40, 50, 60, 70, 80]

[output] | for i in range(1, 11): square = i * i print(square) [instruction] | You need to edit a Python code snippet to add a loop and make it print the square of the numbers from 1 to 10. [input] |

[output] | class ShoeProduct: def __init__(self, name, price, size, color): self.name = name self.price = price self.size = size self.color = color [instruction] | Create a data structure in Python that stores the details of a shoe product. [input] | Name: "Nike Air Max 720" Price: $219.99 Size: 8 Color: White

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