← 목록

Synth · CodeAlpaca일부

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

[output] | def greet(name, message): print(message + " " + name + "!") [instruction] | Add an additional parameter to the following function. [input] | def greet(name): print("Hello " + name + "!")

[output] | SELECT * FROM customers WHERE address LIKE '%Palm Street%'; [instruction] | Write an SQL query to retrieve all the columns from a table named 'customers' where their address includes the string "Palm Street". [input] |

[output] | def calculate_discount(price): return price * 0.8 discount = calculate_discount(price) [instruction] | Create a function `calculate_discount` to calculate 20% discount for a given price. [input] | price = 50

[output] | numbers = [] for num in range (1, end_number+1): numbers.append(num) [instruction] | Create a for loop which will run till the given number and add each number to a list. [input] | end_number = 10

[output] | import json def convert_csv_to_json(csv_string): lines = csv_string.split("\n") keys = lines[0].split(",") out_list = [] for line_num in range(1, len(lines)): line = lines[line_num] values = line.split(",") item = {} for key_num in range(0, len(keys) [instruction] | Create a function called `convert_csv_to_json` to convert the following csv to the corresponding JSON formatt. [input] | city,country,latitude,longitude Frankfurt,Germany,50.1117,8.6785 London,UK,51.4667,-0.25

[output] | def detect_palindrome(string): reversed_string = string[::-1] if (string == reversed_string): return "This string is a palindrome" else: return "This string is not a palindrome" print(detect_palindrome(string)) [instruction] | Create a function that detects whether a given string is a palindrome. [input] | string = ‘level’

[output] | lines = string.split("\n") for line in lines: if line.endswith(character): print(line) [instruction] | Write a code to filter and print all lines that end in the given character. [input] | string = ‘Hello world\nMy name is John\nHello again\nToday is Monday’ character = ‘n’

[output] | for row in range(len(arr)): for col in range(len(arr[row])): if arr[row][col] % 3 == 0: arr[row][col] = 1 print(arr) [instruction] | Assign 1 to all the elements of a 2D array that are divisible by 3. [input] | arr = [[1,2,3], [10,15,20], [3, 8, 6]]

[output] | def binary_search(list, goal): start = 0 end = len(list) - 1 while start <= end: mid = (start + end) // 2 if list[mid] == goal: return mid elif goal < list[mid]: end = mid - 1 else: start = mid + 1 return -1 [instruction] | Create a function named `binary_search` that implement a binary search algorithm. [input] | list = [1, 3, 5, 7, 8, 9, 11] goal = 5

[output] | def replace_words(string, words): for item in words: string = string.replace(item[0], item[1]) return string replaced_string = replace_words(string, words) print(replaced_string) [instruction] | Create a function called `replace_words` which replaces all the words specified in; the given list of words with their corresponding synonyms. [input] | string = “The quick brown fox jumps over the lazy dog” words = [[‘quick’, ‘fast’], [‘lazy’, ‘sluggish’]]

[output] | ^A\w+ [instruction] | Write a regular expression that captures all the words starting with "A". [input] |

[output] | There are three main methods of machine learning: supervised learning, unsupervised learning, and reinforcement learning. In supervised learning, the model is trained using labeled data, that is, data that has its output (or target) value given to the model. Unsupervised learning models learn by ext [instruction] | Differentiate the methods of machine learning and explain the differences. [input] |

[output] | A Support Vector Machine (SVM) is a supervised learning algorithm that can be used for binary classification, regression, or outlier detection. SVMs use a hyperplane to separate data points into two categories, each represented by a different class. The hyperplane divides data points into classes by [instruction] | Explain how a support vector machine works. [input] |

[output] | def print_lsc(x): print(x%10) [instruction] | Write a function that takes an integer as an argument and prints its least significant digit. [input] |

[output] | def square_arr(arr): return [x**2 for x in arr] [instruction] | Create an array of the squared values of all elements of the given array. [input] | arr = [2, 3, 6, 8]

[output] | SELECT * FROM Table WHERE ID > 5; [instruction] | Select all the records in the given table where the ID is greater than 5. [input] | Table ID | Name | Address 1 | John | UK 2 | Jack | US 5 | Mary | UK 11 | Chris | Canada

[output] | def find_min(arr): return min(arr) [instruction] | Write a Python function to find the minimum element from the given array. [input] | arr = [11, 9, 10, 14]

[output] | import sys import re [instruction] | Add an import statement to the code to import the regex module. [input] | import sys

[output] | DELETE FROM Table; [instruction] | Write a query to delete all the rows in the given table. [input] | Table ID | Name | Address 18 | John | UK 2 | Jack | US 6 | Mary | UK 14 | Chris | Canada

[output] | def dict_from_arrs(key_arr, value_arr): return dict(zip(key_arr, value_arr)) [instruction] | Write a Python code to construct a dictionary from the given input. [input] | key_arr = [100, 200, 300] value_arr = ["apple", "banana", "mango"]

[output] | keys = ["key1", "key2", "key3"] dictionary = {key: None for key in keys} print(dictionary) [instruction] | Initialize a dictionary using the given keys. [input] | keys=["key1", "key2", "key3"]

[output] | s1 = "Hello World" s2 = "o" def count_characters(s1, s2): count = 0 for c in s1: if c == s2: count += 1 return count print(count_characters(s1,s2)) [instruction] | Given two strings s1 and s2, find the number of times the characters in s2 are present in s1. [input] | s1 = "Hello World", s2 = "o"

[output] | nums = [1, 2, 4, 6, 7, 8, 10, 12, 14, 18] def filter_divisible_by_6(nums): return [num for num in nums if num % 6 == 0] print(filter_divisible_by_6(nums)) [instruction] | Filter out the integers from the list that are divisible by 6. [input] | nums = [1, 2, 4, 6, 7, 8, 10, 12, 14, 18]

[output] | nums = [-5, -2, 3, 7, 1] def transform(nums): return [abs(num) for num in nums] print(transform(nums)) [instruction] | Transform and print the given list which includes negative and positive numbers. [input] | nums = [-5, -2, 3, 7, 1]

[output] | s = "this is a sample string" c = "s" r = "x" def replace_character(s, c, r): return s.replace(c, r) print(replace_character(s, c, r)) [instruction] | Replace all instances of a given character with another character. [input] | s = "this is a sample string", c="s", r="x"

[output] | pattern = r'\bPy\w*\b' [instruction] | Writing a regex pattern to match words starting with "Py" [input] |

[output] | def printFooBar(x): fooBarArray = [] for i in range(x): fooBarArray.append(i) if len(fooBarArray) > 0: print(fooBarArray) [instruction] | Rewrite the code to remove the unnecessary boolean flag [input] | flag = False def printFooBar(x): fooBarArray = [] for i in range(x): fooBarArray.append(i) flag = True if flag and len(fooBarArray) > 0: print(fooBarArray)

[output] | var multiply = function(x, y) { return x * y; }; [instruction] | Convert the following snippet from ES6 to ES5 [input] | const multiply = ( x, y) => { return x * y };

[output] | State: Texas Color: Blue Animal: Dog [instruction] | Classify the following pieces of data [input] | Texas Blue Dog

[output] | def lcs(str1, str2, n, m): if n == 0 or m == 0: return 0 elif str1[n-1] == str2[m-1]: return 1 + lcs(str1, str2, n-1, m-1) else: return max(lcs(str1, str2, n, m-1), lcs(str1, str2, n-1, m)) [instruction] | Using python, implement a method to find the longest common subsequence in two strings [input] | str1 = "AGGTAB" str2 = "GXTXAYB"

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