← 목록

Synth · CodeAlpaca일부

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

[output] | def squares_sum(arr): sum = 0 for i in range(len(arr)): sum += arr[i] ** 2 return sum [instruction] | Read the integers in a given list and return the sum of the squares of the list elements. [input] | arr = [1, 2, 3]

[output] | print(f"Hello, my name is {name}.") [instruction] | Create a format string in Python to output the sentence “Hello, my name is John Doe.” [input] | name = "John Doe"

[output] | import re words = re.split(r'\s', sentence) print(words) # Output: ['Meeting', 'is', 'at', '4', 'pm'] [instruction] | Split the following sentence into three words using regular expression. [input] | sentence = "Meeting is at 4 pm"

[output] | dictionary = dict.fromkeys(list, 0) print(dictionary) # Output: {'apple': 0, 'banana': 0, 'cherry': 0} [instruction] | Write a Python script to create a dictionary of key - value pairs from a list. [input] | list = ["apple", "banana", "cherry"]

[output] | def sortArray(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] sortArray(arr) print(arr) # Output: [1, 2, 3, 4, 5] [instruction] | Read an array of integers and sort it in increasing order. [input] | arr = [3, 1, 4, 5, 2]

[output] | for i in range(11, 25, 2): print(i) [instruction] | Create a loop in Python to print odd numbers between 10 and 25. [input] |

[output] | def Fibonacci(n): if n==0: return 0 elif n==1: return 1 else: return Fibonacci(n-1)+Fibonacci(n-2) for n in range(10): print(Fibonacci(n)) [instruction] | Edit this code to create a function which prints the Fibonacci series. [input] |

[output] | newList = [i for i in list if len(i) >= 3] print(newList) # Output: ['Apple', 'banana', 'mouse'] [instruction] | Read a list of strings and return a list which contains only the strings with length at least 3. [input] | list = ["Apple", "cat", "dog", "banana", "mouse"]

[output] | public class LeapYear { public static void main(String args[]) { int year = 2020; if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) System.out.println("The year is a leap year."); else System.out.println("The year is not a [instruction] | Create a Java program which takes a year as input and prints whether it is a leap year or not. [input] | year = 2020

[output] | SELECT * FROM Employee ORDER BY Salary DESC LIMIT 10; [instruction] | Write an SQL query that displays the 10 highest paid employees. [input] |

[output] | transpose_matrix = [[1, 4, 7], [2, 5, 8], [3, 6, 9]] [instruction] | Given a 2D array, transpose the array. [input] | matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

[output] | def format_list(numbers): result = [] prod = 1 for i in range(0, len(numbers)): prod = prod * numbers[i] for i in range(0, len(numbers)): result.append(prod // numbers[i]) return result [instruction] | Format the given list of numbers in such a way that element at i'th index is the product of all elements in the list except the i'th element. [input] | numbers = [1, 2, 3, 4]

[output] | def tree_depth(root): # Base case if root is None: return 0 ; # If tree is not empty then height = 1 + max of left # height and right heights return 1 + max(tree_depth(root.left), tree_depth(root.right)) [instruction] | Create a function to compute the depth of a binary tree. [input] |

[output] | def find_pair(numbers, target): nums_set = set(numbers) for num in nums_set: if target - num in nums_set: return [num, target-num] [instruction] | Create a function to find a pair of elements in an array whose sum matches the given target. [input] | numbers = [1, 2, 3, 4, 5], target = 6

[output] | def most_frequent_value(list): return max(set(list), key = list.count) [instruction] | Write a function in Python that takes a list of integer as input and return the most frequent value in the list. [input] | [3, 9, 5, 6, 3, 9, 5]

[output] | h1, h2 { font-size: 40px; } [instruction] | Alter the following CSS code to make font size "40px" for all h1 and h2 elements. [input] | h1, h2 { font-size: 20px; }

[output] | const toTitleCase = (str) => { return str.replace(/\w\S*/g, function(txt){ return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); }); } [instruction] | Create a function in Javascript to be used for capitalizing the first letter of each word in a string of text. [input] |

[output] | const intersection = (arr1, arr2) => arr1.filter(x => arr2.includes(x)); [instruction] | Suggest a one-line solution for intersecting two given arrays in Javascript. [input] |

[output] | const greetUser = (name) => console.log(`Hello ${name}!`); [instruction] | Rewrite the following function to use the modern function syntax in Javascript. [input] | function greetUser(name) { console.log('Hello ' + name + '!'); }

[output] | class Apple { constructor(name){ this.Name = name; } } [instruction] | Create a JavaScript class named “Apple” that holds one property, the “Name”. [input] |

[output] | SELECT flightno, startcity, starttime FROM flights WHERE startcity = 'NYC' AND starttime > '2021-03-16 08:00:00'; [instruction] | Write a SQL query to find all flights departing from a given location after a given date and time. [input] | StartCity: NYC Date/Time: March 16, 2021 8:00 AM

[output] | myObject = { 'color': '', 'height': 0, 'weight': 0 } [instruction] | Create an object in Python that has three properties, "Color", "Height" and "Weight". [input] |

[output] | .big-header { font-size: 24px; } [instruction] | Write a CSS rule to set the text size of all elements with the class “big-header” to 24px. [input] |

[output] | <table> <thead> <tr> <th>Column A</th> <th>Column B</th> <th>Column C</th> </tr> </thead> <tbody> <tr> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td>< [instruction] | Create an HTML table that contains 10 rows and 3 columns. [input] |

[output] | 15 [instruction] | Compute the sum of all the numbers in the following array: [1, 2, 3, 4, 5]. [input] |

[output] | ["Apple", "Banana", "Orange", "Carrot", "Cucumber", "Spinach"] [instruction] | List all the items in an associative array named ‘inventory’. [input] | inventory = { "fruits": ["Apple", "Banana", "Orange"], "vegetables": ["Carrot", "Cucumber", "Spinach"] }

[output] | int sum = 0; for (int i = 0; i < n; i++) sum += i; sum = n * (n + 1) / 2; [instruction] | Edit the following code to use more efficient algorithms to improve its performance. [input] | for (int i = 0; i < n; i++) { sum += i; }

[output] | An array or a list should be used to store the positions of the numbers that are equal to 0 in the input. The output array should be used to store the positions. The output index should be used to keep track of the current position in the output array. [instruction] | Observe the given piece of code and suggest the possible data structure to use. [input] | for (int i = 0; i < input.length; i++) { if (input[i] == 0) { output[output_index] = i; output_index++; } }

[output] | A common approach would be to use an efficient sorting algorithm, such as Quicksort, Merge Sort, or Heapsort. These algorithms typically take time proportional to n log n, where n is the number of elements being sorted. [instruction] | How would you go about sorting a million numbers in memory? [input] |

[output] | # Definition for singly-linked list. class ListNode: def __init__(self, x): self.val = x self.next = None def reverse_list(head): prev = None while head != None: next = head.next head.next = prev prev = head head = next return prev [instruction] | Edit the Python code to reverse a linked list. [input] | # Definition for singly-linked list. class ListNode: def __init__(self, x): self.val = x self.next = None

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