← 목록

Synth · CodeAlpaca일부

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

[output] | def is_divisible_by_seven(ints): return any(num % 7 == 0 for num in ints) [instruction] | Write a Python function that takes a list of integers and returns True if any of the integers is divisible by 7. [input] |

[output] | def compare_strings(s1, s2): s1_chars = list(s1) s2_chars = list(s2) num_diff_chars = 0 for char in s1_chars: if char not in s2_chars: num_diff_chars += 1 for char in s2_chars: if char not in s1_chars: num_diff_chars += 1 return num_dif [instruction] | Write a function to compare two strings and return the number of different characters in each string. [input] |

[output] | function cloneObject(obj){ let newObj = {} for (let key in obj){ if (obj.hasOwnProperty(key)){ newObj[key] = obj[key] } } return newObj } [instruction] | Write a JavaScript function to create a new object from the given object. [input] | obj = { "name": "John", "age": 30 }

[output] | movie_dict = { 'title' : str, 'director' : str, 'producer' : str, 'writer' : str, 'actors' : list, 'release_date' : date, 'runtime_minutes' : int, 'budget' : int, 'production_company' : str, 'box_office' : int, 'genres' : list, 'plot' : str, 'awards' : list, 'language' : [instruction] | Construct a data dictionary for a movie [input] |

[output] | import random import string def secure_password(strong=False): length = random.randint(8, 16) letters = string.ascii_lowercase+string.ascii_uppercase+string.digits if strong: symbols = string.punctuation letters += symbols return ''.join(random.choice(letters) for i [instruction] | Design a function to create a secure password [input] |

[output] | import itertools def anagrams(str): return ["".join(permutation) for permutation in itertools.permutations(str)] print(anagrams(str)) # Output: ['cat', 'cta', 'act', 'atc', 'tca', 'tac'] [instruction] | Write a function to generate anagrams for a given string [input] | str = "cat"

[output] | class TreeNode: def __init__(self, data): self.data = data self.left = None self.right = None def Insert(self, data): if self.data: if data < self.data: if self.left is None: self.left = TreeNode(data) [instruction] | Create a class for constructing a new tree [input] |

[output] | def summation(arr): sum = 0 for i in arr: sum += i return sum print(summation(arr)) # Output: 36 [instruction] | Generate a code snippet to calculate the sum of an array [input] | arr = [1, 23, 4, 3, 5]

[output] | def convert_fahrenheit_to_celsius(temperature): return (temperature - 32) * 5 / 9 [instruction] | Change the following code to convert the temperature from Fahrenheit to Celsius. [input] | def convert_fahrenheit_to_celsius(temperature): return temperature - 32

[output] | import random import string def generate_password(): characters = string.ascii_letters + string.digits + string.punctuation length = 8 password = ''.join(random.choice(characters) for _ in range(length)) while not (any(c.isdigit() for c in password) and any(c.isalpha() for c in pass [instruction] | Generate a password that is at least 8 characters long and contains at least one letter, one number, and one special character. [input] |

[output] | def calculate_power(base, power): if power == 0: return 1 else: return base * calculate_power(base, power - 1) [instruction] | Write a Python function to calculate the power of a number raised to the nth power. [input] |

[output] | def isSameTree(p, q): if p is None and q is None: return True if p is None or q is None: return False if p.val != q.val: return False return isSameTree(p.left, q.left) and isSameTree(p.right, q.right) [instruction] | Submit an optimized solution to the following leetcode problem. [input] | Problem: Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical and the nodes have the same value.

[output] | import datetime def timestamp_to_readable(unix_timestamp): return datetime.datetime.fromtimestamp(unix_timestamp).strftime("%A, %B %d, %H:%M:%S, %Y") [instruction] | Write a Python function to convert a given Unix timestamp to a readable format like "day, month, date, hours:minutes:seconds, year". [input] |

[output] | class Currency: def __init__(self, currency_name, currency_symbol, currency_value): self.name = currency_name self.symbol = currency_symbol self.value = currency_value def __str__(self): return f"{self.name}: {self.symbol}{self.value}" [instruction] | Define a class in Python that represents a currency. [input] |

[output] | (1 % <) [instruction] | Arrange the following characters in a valid Python expression. [input] | <, 1, %, (

[output] | class GameState: def __init__(self): self.board = [[None, None, None], [None, None, None], [None, None, None] ] def is_game_over(self): b = self.board # Check if a player won if b[0][0] == b[0][1] == b[0 [instruction] | Write a Python Function to implement the game of Tic-Tac-Toe. [input] |

[output] | for (int i = 0; i < 10; i++) { System.out.println(i); } [instruction] | Construct a for loop in Java to increment a counter from 0 to 10. [input] |

[output] | The program can be improved to make use of better data structure, such as a list comprehension. This would allow faster iteration over the list and reduce duplicate lines of code. def main(): my_list = [1,2,3,4] my_list = [element for element in my_list] for element in my_list: print( [instruction] | Analyze an object-oriented program written in Python and suggest changes to improve its technical quality. [input] | def main(): my_list = [1,2,3,4] for element in my_list: print(element) if __name__== "__main__" main()

[output] | from sklearn.svm import SVC from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split # Load the iris dataset iris = load_iris() # Split the data into train and test sets X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, [instruction] | Train a machine learning algorithm to classify objects into one of two classes. [input] |

[output] | Create an AWS Lambda function with associated IAM roles and policies that define the function’s access to related AWS resources. Package your code into a .zip file and upload it to AWS Lambda. Connect the Lambda function to an API Gateway to make your function accessible through an API endpoint. [instruction] | Create a serverless application with AWS Lambda. [input] |

[output] | I was strolling through the dense forest when, out of the corner of my eye, I noticed something large and shimmering in the sunlight. As I approached, I saw a magnificent dragon lounging among the trees. Its scales glinted in the sun's rays and its massive, sharply-clawed feet were planted firmly in [instruction] | Edit a first person narrative created by a GPT model in order to make the narrative more coherent. [input] | I was walking in the forest and suddenly I saw a dragon. It was huge and its scales glimmered in the sunlight. It had sharp claws and its eyes were red.

[output] | <html> <head> <title>Population of the World</title> </head> <body> <table> <tr> <th>Country</th> <th>Population</th> </tr> <tr> <td>China</td <td>1,439,323,776</td> </tr> <tr> <td>India</td> <td>1,380,004,385</td> </t [instruction] | Create a HTML page displaying a table holding information about the 10 most populous countries in the world. [input] |

[output] | import random def random_character(strings): return random.choice(strings) random_character(['apple','orange','pineapple','grape']) [instruction] | Generate code which returns a random character from a given list of strings. [input] | ['apple','orange','pineapple','grape']

[output] | 1. Download and install the MongoDB server 2. Create data directories, a log file and a configuration file 3. Update configuration entries to reflect storage capacity and logging preferences 4. Start the MongoDB service 5. Create new users, roles and databases 6. Connect applications to MongoDB [instruction] | Install and set up a database management system called MongoDB. [input] |

[output] | import java.net.*; import java.io.*; public class HttpClient { public static void main(String[] args) { try { URL url = new URL("http://example.com/api/login"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); // Request headers con.setRequest [instruction] | Use Java to send an HTTP request to an API endpoint with a login form. [input] |

[output] | public class LongestIncreasingSubsequence { public static int longestSubsequence (int[] nums) { // Base case if (nums.length == 0) { return 0; } int[] dp = new int[nums.length]; dp[0] = 1; int maxLength = 1; for (int i=1; [instruction] | Create a Java program that takes a list of integers as an argument and computes the longest increasing subsequence. [input] | [8, 10, 1, 4, 15, 6, 7]

[output] | def linkedListSubtract(l1, l2): dummy_node = ListNode(0) current = dummy_node carry = 0 while l1 or l2: curr_value1 = 0 curr_value2 = 0 if l1 : curr_value1 += int(l1.val) l1 = l1.next if l2 : curr_value2 += int(l2. [instruction] | Implement an algorithm to subtract two strings, represented as a linked list, in the order they appear in and return the result as a linked list. [input] | l1 = ["1","2","3"], l2 = ["9","2"]

[output] | function flatten(arr) { const flattened = []; // Call the function recursively const flattenHelper = (a) => { for (let i = 0; i < a.length; i++) { Array.isArray(a[i]) ? flattenHelper(a[i]) : flattened.push(a[i]); } }; flattenHelper(arr); return flattened; } [instruction] | Write a function in JavaScript to flatten the given array. [input] | [1, [[2, 3], 4], 5, [6]]

[output] | int min; if (num1 < num2) { min = num1; } else { min = num2; } [instruction] | Modify this C program to minimize the number of lines without applying the ternary operator. [input] | int min = num1 < num2 ? num1 : num2;

[output] | function is_anagram($s1, $s2) { // If the lengths of the strings are not equal, // they cannot be anagrams if (strlen($s1) != strlen($s2)) { return false; } // Create an array and assign value 0 to each character $count = array(); for ($i = 0; $i < strlen( [instruction] | Build a PHP function to check if two strings are anagrams. [input] | $s1 = 'abcd'; $s2 = 'dcba';

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