← 목록

Synth · CodeAlpaca일부

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

[output] | def partition(lst): left_sum, right_sum = 0, sum(lst) for i in range(len(lst)-1): left_sum += lst[i] right_sum -= lst[i] if left_sum > right_sum: return lst[:i+1], lst[i+1:] return None [instruction] | Given a list of numbers, write a program which partitions the list into two parts, such that the sum of the elements in the first part exceeds the sum of the elements in the second part. [input] |

[output] | def sum_multiples(lst, n): return sum([i for i in lst if i % n == 0]) [instruction] | Calculate the sum of all numbers in the given array that are multiples of the given number. [input] | numbers=[2, 4, 6, 8, 10, 12] num=3

[output] | def sum_of_cube_of_digits(num): sum = 0 while (num > 0): digit = num % 10 sum += digit**3 num //= 10 return sum [instruction] | Design a function which takes a parameter and returns the sum of its cube of its digits [input] |

[output] | def sort_dict_by_values(dict_list): return sorted(dict_list, key=lambda k: k['value']) [instruction] | How can you sort a list of dictionaries by values of the dictionary in Python? [input] |

[output] | class PriorityQueue: def __init__(self): self.queue = [] # Create the enqueue(data) method to add data inside the queue def enqueue(self, data): self.queue.append(data) # Create the dequeue() method to remove data from the queue def dequeue(self): if s [instruction] | Write code to implement a priority queue in Python. [input] |

[output] | def char_by_char(string): for char in string: print(char) [instruction] | How can you print a string character by character in Python? [input] |

[output] | num = 10121 total = 0 while num > 0: digit = num%10 total += digit num //= 10 print(total) [instruction] | Suggest a completion for the following code which will print the sum of all digits in the given number. [input] | num = 10121 total = 0 while num > 0:

[output] | import random def generate_random_array(): array = [] for i in range(10): array.append(random.randint(1,100)) return array [instruction] | How can you generate a random array of 10 integers between 1 and 100? [input] |

[output] | let arr1 = [1,2,3]; let arr2 = [4,5,6]; arr2.push(...arr1); // arr2 is [4,5,6,1,2,3] [instruction] | Write a JavaScript code snipplet that append the contents of one array to another array. [input] | let arr1 = [1,2,3]; let arr2 = [4,5,6];

[output] | let sum = 0; for(let i = 1; i <= 100; i++) { sum += i; } [instruction] | Write a code snipplet that computes the sum of numbers between 1 and 100. [input] |

[output] | SELECT name, age FROM employees GROUP BY age; [instruction] | Write an SQL query to group the results of a SELECT statement according to the value of a specific column. [input] | SELECT name, age FROM employees;

[output] | def dict_to_tuple(dictionary): return [(key, value) for key, value in dictionary.items()] [instruction] | Write a Python function to convert a dictionary into a list of tuples. [input] | dictionary = { "name": "John", "age": 36 }

[output] | Object-oriented programming (OOP) is a programming language model in which programs are organized around objects rather than actions and data rather than logic. OOP languages allows the programmer to think in terms of classes and objects which makes it easier to maintain and modify existing code. In [instruction] | Explain what an object-oriented programming language is. [input] |

[output] | # load the data data <- read.csv("data.csv") # fit the model model <- lm(formula = response ~ predictor, data = data) # view the results summary(model) [instruction] | Write an R script that performs linear regression to predict a response variable. [input] |

[output] | A Turing Test is a measurement of a machine's ability to exhibit intelligent behaviour equivalent to, or indistinguishable from, that of a human. The test was proposed by Alan Turing in 1950 as a way of determining whether a machine is capable of intelligent thought. The Turing Test consists of a hu [instruction] | Identify and explain the purpose of a Turing Test. [input] |

[output] | def printString(string): print(string) [instruction] | Convert the following English sentence into a Python function definition: "Prints a string on the screen". [input] |

[output] | A for loop in Python is a type of looping construct that is used to iterate over a sequence of objects including strings, lists, tuples, dictionaries, and sets. A for loop has three components, the iterator (variable), sequence, and statements. With each iteration, the iterator is assigned the value [instruction] | Describe how the for loop works in Python? [input] |

[output] | function generatePassword(){ var charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#%^&*()_+-="; var passwordLength = Math.floor(Math.random() * (10 - 8 + 1)) + 8; var password = ''; for(let i = 0; i < passwordLength; i++){ var randomChar = charSet[Math.floor( [instruction] | Write a JavaScript function to generate a random strong password with length 8-10. [input] |

[output] | #include <stdio.h> int main() { double x, y, sum; printf("Enter two numbers: "); scanf("%lf%lf", &x, &y); sum = x + y; printf("Sum of the entered numbers: %lf", sum); return 0; } [instruction] | Write a C program to implement a simple calculator that adds two numbers. [input] |

[output] | Python List Comprehensions allow users to quickly build a list from another list or an iterable. List Comprehensions use a syntax that consists of an expression followed by a ‘for’ statement and then zero or more ‘for’ or ‘if’ clauses. The expression is evaluated once for each item in the list. List [instruction] | Explain how Python List Comprehensions work? [input] |

[output] | SELECT Name, SUM(Salary) AS Total_Salary FROM Employees WHERE Department = 10 AND Salary > ( SELECT AVG(Salary) FROM Employees WHERE Department = 10 ) GROUP BY Name; [instruction] | Write a MySQL query to display the name and total salary of employees who earn more than the average salary of department 10. [input] | Table "Employees": Name | Department | Salary ------ | ---------- | ------ John | 10 | 20000 David | 10 | 32000 Anne | 10 | 15000 Jane | 11 | 26000

[output] | SELECT AVG(Salary) as Mean, PERCENTILE_DISC(0.5) WITHIN GROUP(ORDER BY Salary) OVER() as Median FROM Employees [instruction] | Write a SQL query to find the mean and median of all salaries of employees. [input] | Table "Employees": Name | Salary ---- | ------ John | 20000 David| 32000 Anne | 15000 Jane | 26000

[output] | def delete_duplicate(lst): new_lst = [] for i in lst: if i not in new_lst: new_lst.append(i) return new_lst lst = [3,6,3,7,2,6] new_lst = delete_duplicate(lst) print(new_lst) [instruction] | Write a script to delete elements that appear twice or more from a list. [input] | [3,6,3,7,2,6]

[output] | The best data structure to store a large set of strings efficiently is a hash table. A hash table uses a hash function to map a set of strings to unique indices in an array, which allows for constant time lookups and operations. [instruction] | Name a data structure to store a large set of strings efficiently. [input] |

[output] | A string can be encoded in base64 by using the string's bytes as input to the base64 encoding algorithm. The base64 encoding algorithm works by taking 3 bytes of input data and converting them into 4 bytes of output data. Each of these 4 bytes represent 6 bits of the original string, which is repres [instruction] | How can a string be encoded in base64? [input] |

[output] | def generate_string(lst): s = "" for i in lst: s+=str(i) return s lst = [1, 2, 3, 4] s = generate_string(lst) print(s) [instruction] | Generate the following string from a list. [input] | [1, 2, 3, 4]

[output] | def display_char(s): for char in s: print(char) s = "Hello World!" display_char(s) [instruction] | Construct a loop to display each character in a string one at a time. [input] | Hello World!

[output] | def find_missing(nums): count = 1 for num in nums: if not count in nums: return count count += 1 return None [instruction] | Design an algorithm to check for missing numbers in an array of size n. [input] |

[output] | def find_longest_substring(string): max_length = 0 for i in range(len(string)): seen_chars = set() length = 0 for j in range(i, len(string)): if string[j] not in seen_chars: seen_chars.add(string[j]) length += 1 [instruction] | Create an algorithm to find the longest substring of a given string with distinct characters. [input] | Given string = "abcabcabc"

[output] | #include <bits/stdc++.h> using namespace std; int most_common(int arr[], int n) { unordered_map<int, int> hash; // store the counts of all elements for (int i = 0; i < n; i++) hash[arr[i]]++; // traverse through the map and // find out the maximum frequency int [instruction] | Create a C++ program that finds the most common element in the given input array. [input] | Given array = [2, 4, 8, 3, 4, 4, 6, 2, 4, 9]

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