← 목록

Synth · CodeAlpaca일부

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

[output] | def multiply_without_operator(a, b): # If either a or b = 0, return 0 if (a == 0 or b == 0): return 0 # Initialize result result = 0 # Add a, b number of times for i in range(min(a, b)): result = result + max(a, b) # Return the multiplicatio [instruction] | Generate an algorithm to multiply two numbers without using multiplication operator [input] |

[output] | def print_unique(s): output = set() for char in s: if char not in output: output.add(char) print(char) [instruction] | Suggest a valid Python code to print unique characters of a given string [input] |

[output] | ^www\.somedomain\.com\/posts\/\d+$ [instruction] | Create a regex pattern that can match the pattern "www.somedomain.com/posts/[post_id]". [input] |

[output] | import json def parse_json(json_data): data = json.loads(json_data) return data if __name__ == '__main__': json_data = '{"name": "John Doe", "age": "35"}' print(parse_json(json_data)) [instruction] | Parse a JSON response into a Python dictionary. [input] | { "name": "John Doe", "age": "35" }

[output] | In JavaScript, lists of elements can be defined using an array. An array is a data structure that stores a set of elements of the same type. The elements of an array can be accessed by their index. Example: var myList = ['item1', 'item2', 'item3']; [instruction] | How can you define a list of elements in JavaScript? [input] |

[output] | .button { display: inline-block; padding: 0.5rem; font-size: 1rem; background-color: #1e85e7; color: #fff; border-radius: 0.25rem; border: 0; cursor: pointer; } [instruction] | Create a CSS class called "button" to style a button [input] |

[output] | dic = {"min": 10, "max": 20} [instruction] | Fix the following Python code to create a dictionary. [input] | dic = {“min”, 10, “max”, 20}

[output] | def generate_dict(): """Generate a dictionary with the key-value pairs {1:1, 2:4, 3:9, 4:16}""" my_dict = {} for i in range(1, 5): my_dict[i] = i**2 return my_dict generate_dict() # Outputs {1:1, 2:4, 3:9, 4: 16} [instruction] | Generate a dictionary with the key-value pairs {1:1, 2:4, 3:9, 4:16} [input] |

[output] | def remove_duplicates(arr): """Remove the duplicates from the list without using built-in methods.""" # Initialize empty list new_list = [] # Iterate through array for num in arr: # Check if element is not in list if num not in new_list: # Add element [instruction] | Remove the duplicates from the list without using built-in methods. [input] | [1, 2, 1, 2, 3, 2, 4, 2]

[output] | def insertion_sort_reverse(arr): """ Sort the list in reverse order using insertion sort. """ # Iterate over the list for i in range(1, len(arr)): current_value = arr[i] # Keep track of position position = i # Iterate over the sorted part of the list [instruction] | Sort the list in reverse order using insertion sort. [input] | [4, 2, 0, 6, 1, 7, 3]

[output] | import datetime def convert_to_timestamp(date_string): """Write a code to convert a given date string into a timestamp.""" date_object = datetime.datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S') timestamp = datetime.datetime.timestamp(date_object) return timestamp convert_to_tim [instruction] | Write a code to convert a given date string into a timestamp. [input] | date_string = "2020-07-24 14:50:00"

[output] | import re pattern = r"^[0-9]*(3|6|9)$" re.match(pattern, "6") # Outputs <re.Match object; span=(0, 1), match='6'> [instruction] | Create a regular expression which will match numbers divisible by 3. [input] |

[output] | def multiply_by_3(arr): """Multiply each element in the given array by 3 and return the new array.""" # Initialize empty array new_arr = [] # Iterate over the array for num in arr: # Multiply by 3 num *= 3 # Append to new array new_arr.append(num) [instruction] | Multiply each element in the given array by 3 and return the new array. [input] | [1, 2, 3]

[output] | def split_and_remove(string): """In the given string, split the words and remove empty strings.""" # Split the string by spaces arr = string.split(' ') # Initialize empty list new_arr = [] # Iterate over array for word in arr: # Check if not empty if word [instruction] | In the given string, split the words and remove empty strings. [input] | string = " Hello World "

[output] | def create_frequency_dict(string): """Create a dictionary containing the characters from the given string as keys and their frequency in the string as values.""" # Initialize empty dictionary freq_dict = {} # Iterate over the string for char in string: # Check if char is [instruction] | Create a dictionary containing the characters from the given string as keys and their frequency in the string as values. [input] | string = 'google'

[output] | SELECT * FROM table ORDER BY name ASC; [instruction] | Write a query to sort a table data by their names in alphabetical order. [input] |

[output] | for (let i = 0; i < arr.length; i++) { console.log(arr[i]); } [instruction] | Write a JavaScript loop to print out all the values of an array. [input] | arr = [1, 2, 3, 4, 5]

[output] | def get_n_dimensional_vectors(n): vectors = [[0 for x in range(n)] for x in range(len(arr))] for vector in vectors: for i in range(n): vector[i] = arr[i] return vectors [instruction] | Give a function to get an array of n-dimensional vectors. [input] |

[output] | def convert_base(num, from_base, to_base): if isinstance(num, str): n = int(num, from_base) else: n = int(num) alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" if n < to_base: return alphabet[(n)] else: return convert_base(n // to_base, from_base [instruction] | How can you convert a number from one base to another? [input] |

[output] | The transitive closure of the 'less than' relation on the set of integers is defined as: if (x,y) belongs to the set of integers, then for all n, x < n and n < y implies x < y. [instruction] | Answer this logic programming question: What is the transitive closure of the binary relation "less than" on the set of integers? [input] |

[output] | def pairs_with_sum(arr, value): pairs = [] for i in range(len(arr)-1): for j in range(i+1, len(arr)): if (arr[i] + arr[j] == value): pairs.append((arr[i], arr[j])) return pairs [instruction] | Write a function in Python which takes an array of integers and returns a list of all distinct pairs whose sum is equal to a given value. [input] | arr = [1, 2, 3, 4, 5] value = 7

[output] | <ul> <li>First item</li> <li>Second item</li> <li>Third item</li> </ul> [instruction] | Use the following HTML to create an unordered list. [input] | <ul><li>First item</li> <li>Second item</li> <li>Third item</li></ul>

[output] | CREATE PROCEDURE intersection(table1 VARCHAR(255), table2 VARCHAR(255)) BEGIN SELECT * FROM table1 WHERE EXISTS (SELECT * FROM table2 WHERE table1.columnName = table2.columnName); END; [instruction] | Write a procedure in SQL that takes two tables as parameters and returns the intersection of the two. [input] | table1, table2

[output] | import json users = [ { "name": "Peter", "age": 25 }, { "name": "Theresa", "age": 30 }, { "name": "John", "age": 22 } ] for user in users: print("Name: "+ user["name"] + ", Age: " + str(user["age"])) [instruction] | Use the following JSON data to output information about all the users in the array. [input] | [ { "name": "Peter", "age": 25 }, { "name": "Theresa", "age": 30 }, { "name": "John", "age": 22 } ]

[output] | const calculator = { sum: function(a, b){ return a + b; }, product: function(a, b){ return a * b; } }; [instruction] | Create an object in JavaScript that contains two methods. The first method takes two parameters and returns the sum of the two numbers, and the second method takes two parameters and returns the product of the two numbers. [input] |

[output] | """ Find the mean rental price for a property in Miami, Florida using the Pandas library. """ import pandas as pd # read the dataset df = pd.read_csv('data.csv') # filter the data by city df_miami = df[df['city'] == 'Miami, Florida'] # calculate the mean rental price mean_price = df_miami['renta [instruction] | Use the Pandas library to find the mean rental price for a property in a particular city in the US. [input] | The property is located in Miami, Florida.

[output] | One way to find the maximum depth of a tree data structure is to start at the root node and then recursively traverse down each branch, keeping track of the maximum depth. This is known as a depth-first search and can be implemented using a recursive algorithm. Alternatively, the maximum depth can a [instruction] | How would you find the maximum depth of a tree data structure? [input] |

[output] | """ Create a Python function which takes in a list and returns the length of the longest common subsequence of consecutive elements. """ def long_consec_sequence(lst): if not lst: return 0 # initialize the size of the longest subsequence max_seq_len = 0 # iterate [instruction] | Create a Python function which takes in a list and returns the length of the longest common subsequence of consecutive elements in the list. [input] | [1, 3, 5, 8, 9, 10, 11, 15]

[output] | """ Create a function to check whether a number is a prime number using the Sieve of Eratosthenes algorithm. """ def is_prime(n): if n <= 1: return False # create a list of all numbers from 0 to n nums = [True for _ in range(n + 1)] p = 2 while (p * p <= n): [instruction] | Create a function to check whether a number is a prime number using the Sieve of Eratosthenes algorithm. [input] |

[output] | One way to reverse a singly linked list without using any additional data structures is to iterate through the linked list, while keeping track of the current node's predecessor and successor. At each iteration, store the predecessor and successor, remove the link from the predecessor to the current [instruction] | How would you reverse a singly linked list without using any additional data structures? [input] |

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