← 목록

Synth · CodeAlpaca일부

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

[output] | """ Sort a list of words by the frequency of their occurrence """ def sort_words_by_frequency(words): frequency_dict = {} for word in words: if word in frequency_dict: frequency_dict[word] += 1 else: frequency_dict[word] = 1 sorted_words = sorted [instruction] | Sort a list of words by the frequency of their occurrence. [input] | dog cat bed dog mouse rat

[output] | """ Generate a random password of length 16 using the letters a-z """ import random def generate_password(): letters = 'abcdefghijklmnopqrstuvwxyz' return ''.join(random.choice(letters) for i in range(16)) if __name__ == '__main__': print(generate_password()) [instruction] | Generate a random password of length 16 using the letters a-z. [input] |

[output] | """ Create a function that can concatenate two lists into a string separated by comma """ def concat_lists(list1, list2): return ','.join([str(i) for i in list1 + list2]) if __name__ == '__main__': print(concat_lists([1, 2, 3], [4, 5, 6])) [instruction] | Create a function that can concatenate two lists into a string separated by comma. [input] | [1, 2, 3] [4, 5, 6]

[output] | """ Create a class that can represent a 2D coordinate system """ class CoordinateSystem: def __init__(self,x,y): self.x = x self.y = y def add(self,other): x = self.x + other.x y = self.y + other.y return CoordinateSystem(x,y) if __name__ == '__main__': a = Coordinate [instruction] | Create a class that can represent a 2D coordinate system. [input] |

[output] | """ Given a set of points and an origin point, calculate the distance between the origin point and each point in the set """ import math def points_distance(points, origin): distances = [] for point in points: distances.append(math.sqrt((point[0]-origin[0])**2 + (point[1]-origin[1] [instruction] | Given a set of points and an origin point, calculate the distance between the origin point and each point in the set. [input] | [(1,1),(4,4),(3,3)] (0,0)

[output] | """ Create a function that can tranform a string of text into an object containing the number of occurrences of each letter in the string """ def count_letters(s): letter_dict = {} for letter in s: if letter in letter_dict: letter_dict[letter] += 1 else: letter_dict[letter] = [instruction] | Create a function that can transform a string of text into an object containing the number of occurrences of each letter in the string. [input] | Hello World

[output] | """ Create a function that takes two strings as input and returns true if the characters in one of the string appear in order in the other string """ def is_substring(str1, str2): i = 0 for char in str2: if char == str1[i]: i += 1 if i == len(str1): return True return False [instruction] | Create a function that takes two strings as input and returns true if the characters in one of the string appear in order in the other string. [input] | mystring isthis

[output] | def get_max(int_list): return max(int_list) [instruction] | Create a function which takes a list of integers as input, and returns the max value of the list. [input] | [7, 9, 5]

[output] | def rotate_2d_matrix(matrix): n = len(matrix[0]) m = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): m[i][j] = matrix[n-j-1][i] return m [instruction] | Implement a function that takes a 2D matrix and rotates the matrix 90 degrees clockwise. [input] | [[1,2,3], [4,5,6], [7,8,9]]

[output] | def num_distinct_substrings(S, k): n = len(S) distinct_substrings = set() for i in range(n): for j in range(i+k, n+1): distinct_substring = "".join(sorted(list(set(S[i:j])))) distinct_substrings.add(distinct_substring) return len(distinct_substrings) [instruction] | Write a function that takes a string and returns the number of substrings with at least k different characters [input] | "abacdc"

[output] | def shortest_increasing_subarray(nums): res, curr = float('inf'), 0 for i in range(len(nums)-1): if nums[i] < nums[i+1]: curr += 1 else: res = min(res, curr) curr = 0 return max(res, curr) + 1 [instruction] | Write a function that takes a list of integers and returns the shortest continuous increasing subarray in the list. [input] | [2,3,3,4,3,4,5,6,7]

[output] | def print_string_keys(json_object): for key in json_object: if isinstance(json_object[key], str): print(key) [instruction] | Create a function that takes a single-level JSON object as an argument and prints out all keys with a value of type string. [input] | { "name": "John", "age": 34, "isMarried": True }

[output] | def is_palindrome_ignore_space(word): filtered_word = [i.lower() for i in word if i.isalpha()] return filtered_word == filtered_word[::-1] [instruction] | Write a Python function to check whether a string is a palindrome or not, ignoring spaces and special characters. [input] |

[output] | def deep_copy(json_object): import json return json.loads(json.dumps(json_object)) [instruction] | Write a function to create a deep copy of a JSON object. [input] |

[output] | class FrequencyTable: def __init__(self, arr): self.table = {} for num in arr: if num in self.table: self.table[num] += 1 else: self.table[num] = 1 def query(self, num): return self.table.get(num, 0) [instruction] | Create a class in Python to build a Frequency Table from a given array of numbers. [input] | [1,1,1,2,2,3,3,3]

[output] | def max_sum_path(matrix): rows, columns = len(matrix), len(matrix[0]) dp = [[float("-inf") for i in range(columns)] for j in range(rows)] dp[0][0] = matrix[0][0] for i in range(rows): for j in range(columns): if i > 0: dp[i][j] = max(dp[i][j], dp[i [instruction] | Given a 2D matrix of integers, find a path from the leftmost column to the right-most column that maximises the sum of numbers. [input] | [[3,4,7,2], [2,7,4,1], [7,1,2,4], [8,2,2,7]]

[output] | def max_sum_submatrix(matrix): rows, columns = len(matrix), len(matrix[0]) dp = [[0] * columns for _ in range(rows)] for i in range(rows): for j in range(columns): dp[i][j] = matrix[i][j] if i > 0: dp[i][j] += dp[i-1][j] if j > [instruction] | Given a 2D matrix of integers, retrive the maximum sum submatrix. [input] | [[2,-2,3,4],[-4,-3,1,1],[-1,5,5,-3]]

[output] | def is_ascending_order(nums): if len(nums) == 0 or len(nums) == 1: return True if nums[0] < nums[1]: return is_ascending_order(nums[1:]) return False [instruction] | Write a function that checks if a given list of integers is sorted in ascending order. [input] |

[output] | def find_empty_position(array1, array2): results = [] for i in range(len(array1)): for j in range(len(array1[0])): if array1[i][j] == array2[i][j] and array1[i][j] == 0: results.append((i, j)) return results [instruction] | Given a 2D array of binary values and another 2D array, find the indices of the first array where the values of both arrays are equivalent. [input] | array1 = [[1, 0, 0, 1],[1, 0, 1, 0],[0, 0, 0, 1],[1, 0, 1, 0]] array2 = [[1, 0, 1, 0], [1, 0, 0, 1], [0, 0, 0, 1], [1, 0, 0, 1]]

[output] | var obj = { name: ''}; [instruction] | Create a new object in JavaScript and assign it a property called "name". [input] |

[output] | int array_count_elements(int array[]) { int count = 0; while (array[count] != '\0') { count++; } return count; } [instruction] | How can we create a function in C that prints the number of elements in an array? [input] |

[output] | print("Welcome to the Text-Based Adventure Game!") player_name = input("What is your name? ") print("Hello " + player_name + ", let's begin!") print("You are walking through a dark forest, it is very quiet and there is a strange feeling of unease") while True: print("What do [instruction] | Create a text-based game in Python. [input] |

[output] | SELECT DISTINCT month, year FROM Appointments; [instruction] | Write an SQL query to identify unique months and years that appear in a table. [input] | Table: Appointments id | month | year

[output] | """ Find the two largest numbers in an array and return them in reverse order """ array = [7,2,9,3,1,5] def largest_numbers(array): largest = 0 second_largest = 0 for i in array: if i > largest: second_largest = largest largest = i elif i > seco [instruction] | Write a code to find the two largest numbers in an array and return them in reverse order. [input] | array = [7,2,9,3,1,5]

[output] | """ Output true if a given expression evaluates to true and false if it doesn't """ expression = "2 + 2 == 4" def evaluate_expression(expression): return eval(expression) if __name__ == '__main__': print(evaluate_expression(expression)) [instruction] | Output true if a given expression evaluates to true and false if it doesn't. [input] | expression = "2 + 2 == 4"

[output] | The reduce() function in Python is used to apply a particular function passed in its argument to all of the list elements mentioned in the sequence passed along. This function is defined in the “functools” module. It applies the function in a manner that the resultant of the function of the current [instruction] | Describe how to use the reduce() function in Python. [input] |

[output] | The easiest way to check if a list of integers contains only even numbers is to iterate over the list and check if each element is divisible by 2. If all elements are divisible by 2, then the list contains only even numbers. def check_even(nums): for num in nums: if num % 2 != 0: [instruction] | How would you check if a list of integers contains only even numbers? [input] |

[output] | #!/bin/bash string="This is a sentence with words of different lengths" # Separate the sentence into words words=($string) # Declare variables max_length=0 result="" # Iterate over each word and find the one with the maximum length for word in "${words[@]}"; do length=${#word} if (( length [instruction] | Write a shell script to print the longest word in a sentence. [input] | string = "This is a sentence with words of different lengths"

[output] | def binary_search(arr, x): start = 0 end = len(arr) - 1 while start <= end: mid = start + (end - start) // 2 if arr[mid] == x: return mid elif arr[mid] < x: start = mid + 1 else: end = mid - 1 return -1 [instruction] | Rewrite this function to use a binary search instead. [input] | def linear_search(arr, x): for i in range (len(arr)): if arr[i] == x: return i return -1

[output] | function normalizeString(str) { return str.replace(/ +/g, ' ').trim(); } normalizeString(myString); // Returns "Hello World" [instruction] | Normalize a string by replacing all sequence of whitespaces with a single space. [input] | var myString = " Hello World "

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