← 목록

Synth · CodeAlpaca일부

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

[output] | import random import string def generate_password(length): password = ''.join(random.choice(string.ascii_letters + string.digits) for i in range(length)) if any(char.islower() for char in password) and any(char.isupper() for char in password) and any(char.isdigit() for char in password): [instruction] | Generate a random password that complies with certain conditions. [input] |

[output] | def transpose_matrix(matrix): transposedMatrix = [[matrix[j][i] for j in range(len(matrix))] for i in range(len(matrix[0])) ] return transposedMatrix transposedMatrix = transpose_matrix(matrix) print(transposedMatrix) [instruction] | Create a script to transpose a matrix. [input] | matrix = [[1,2,3],[4,5,6],[7,8,9]]

[output] | my_list = [0] * n print(my_list) [instruction] | Initialize a list of length n using an input n. [input] | n = 10

[output] | ^6\d{3}$ [instruction] | Write a RegEx to match all numeric strings that start with 6 and contain 4 characters. [input] |

[output] | def to_title_case(word): return word[0].upper() + word[1:].lower() [instruction] | Create a function to convert a given word to title case. [input] |

[output] | def check_zero(matrix): for row in matrix: for num in row: if num == 0: return True return False print(check_zero(matrix)) [instruction] | You are given a matrix. Construct a for loop to check if any of the elements in the matrix is 0. [input] | matrix = [[1,2,3],[4,0,6],[7,8,9]]

[output] | import re pattern = re.compile(r'^[0-9]{4}\s[0-9]{4}\s[0-9]{4}\s[0-9]{4}$') [instruction] | Create a regular expression to match the pattern of a 4-digit credit card number such as '1234 5678 9012 3456'. [input] |

[output] | def reverse_words(sentence): words = sentence.split(' ') reversed_words = [word[::-1] for word in words] return ' '.join(reversed_words) print(reverse_words('I am a programmer')) # Outputs: "I ma a remmargorp" [instruction] | Reverse the words of a given sentence but keep the order of the words intact. [input] | I am a programmer

[output] | def flatten_array(array): result = [] for sub_array in array: result.extend(sub_array) return result print(flatten_array([[1, 2], [3, 4]])) # Outputs: [1,2,3,4] [instruction] | Create a program to convert a bi-dimensional array into a single array. [input] | [[1, 2], [3, 4]]

[output] | def two_sum_elements(arr, target): for i in range(len(arr)): for j in range(i + 1, len(arr)): if arr[i] + arr[j] == target: return [arr[i], arr[j]] return None print(two_sum_elements([1, 8, 10, 12], 18)) # Outputs: [8, 10] [instruction] | Find the two elements in a given array that sums up to the target number. [input] | [1, 8, 10, 12], target = 18

[output] | the [instruction] | Output the word which has maximum frequency in a given string. [input] | The sun has set and the moon has risen.

[output] | [4, 3, 2, 1] [instruction] | Given an array, reverse the elements inside it so that the first element becomes the last and vice versa. [input] | [1, 2, 3, 4]

[output] | ['I', 'LOVE', 'CODING'] [instruction] | Parse a string of words and output an array containing only the uppercase words. [input] | "I Love Coding"

[output] | [6, 15] [instruction] | Given an array containing integers, calculate the sum of the elements in each row and print the result. [input] | [[1, 2, 3], [4, 5, 6]]

[output] | SELECT * FROM employees WHERE years_in_company > 20; [instruction] | Create a query that displays the employees who are completed more than 20 years in the company. [input] |

[output] | for (int i = 0; i < n; i++) { int j = 0; System.out.println("The value of j is: " + j); } [instruction] | Automatically reformat the following code to be more readable: [input] | for (int i=0;i<n;i++){int j=0;System.out.println("The value of j is: "+j);

[output] | SELECT name, (salary / (SELECT MAX(salary) FROM employee)) * 100 AS salary_percentage FROM employee; [instruction] | Write a SQL query to list the salary of all employees as a percentage of the salary of the highest paid employee. [input] |

[output] | def sumNonDuplicates(arr): sum = 0 for num in arr: if arr.count(num) == 1: sum += num return sum [instruction] | Write a function that given a list of unique integers, returns the sum of the non-duplicated integer elements. [input] | [1, 2, 2, 3, 4, 5, 6]

[output] | [2, 3, 5] [instruction] | Output an array with all the prime numbers between 2 and n. [input] | 6

[output] | """ An algorithm that takes two numbers a and b and returns the largest number """ def get_largest_number(a, b): if (a > b): return a else: return b if __name__ == "__main__": print (get_largest_number(5, 6)) [instruction] | Create an algorithm that takes two numbers a and b and returns the largest number. [input] | a = 5, b = 6

[output] | """ Given a string, print all its permutations """ def permute(string): if len(string) == 1: return string permutations = [] for i,c in enumerate(string): for perm in permute(string[:i]+string[i+1:]): permutations.append(c+perm) return permutations if __n [instruction] | Given a string, print all its permutations. [input] | british

[output] | """ Create a class called "Vector" with x and y coordinates """ class Vector: def __init__(self, x, y): self.x = x self.y = y if __name__ == "__main__": v = Vector(2, 3) print (v.x, v.y) [instruction] | Create a class called "Vector" with x and y coordinates. [input] |

[output] | """ Write a function that takes a sentence and returns the reversed version of that sentence """ def reverse_sentence(sentence): word_list = sentence.split() reversed_str = " ".join(word_list[::-1]) return reversed_str if __name__ == "__main__": print(reverse_sentence("Hello, world [instruction] | Write a function that takes a sentence and returns the reversed version of that sentence. [input] | Hello, world!

[output] | """ Design a simple calculator program using a switch statement """ def calculator(operator, x, y): switch = { '+': x + y, '-': x - y, '*': x * y, '/': x / y } return switch.get(operator, "Invalid operator") if __name__ == "__main__": print(calculato [instruction] | Design a simple calculator program using a switch statement. [input] |

[output] | void sort(int array[], int arraySize) { for (int i = 0; i < arraySize-1; i++) for (int j = 0; j < arraySize-i-1; j++) if (array[j] > array[j+1]) { int temp = array[j]; array[j] = array[j+1]; array[j+1] = t [instruction] | Implement a sorting algorithm to sort a given array of size 10. [input] | array: [2, 3, 5, 7, 1, 4, 6, 9, 8, 0]

[output] | <table> <tr> <th>Name</th> <th>Age</th> </tr> <tr> <td>John</td> <td>20</td> </tr> <tr> <td>Alice</td> <td>22</td> </tr> </table> [instruction] | Generate HTML table with a given list of dictionaries. [input] | [{'name': 'John', 'age': 20}, {'name': 'Alice', 'age': 22}]

[output] | def exponent(base, exp) result = 1 exp.times { result *= base } result end [instruction] | Design a function in Ruby to calculate the exponent of a given base and exponent. [input] |

[output] | """ Format this list such that each element is in a new line """ list_of_numbers = [1,2, 3, 4, 5] # Format the list such that each element is in a new line for num in list_of_numbers: print(num) [instruction] | Format this list such that each element is in a new line. [input] | list_of_numbers = [1,2, 3, 4, 5]

[output] | """ Sort this list in a descending order """ my_list = [1,9,3,5,7] # Sort the list in a descending order my_list.sort(reverse=True) print(my_list) [instruction] | Create a code to sort this list in a descending order [input] | my_list = [1,9,3,5,7]

[output] | """ Calculate the sum of the elements in this list """ my_list = [2,5,4,7,5] # Calculate the sum of the elements in this list total = 0 for num in my_list: total += num print(total) [instruction] | Calculate the sum of the elements in this list. [input] | my_list = [2,5,4,7,5]

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