← 목록

Synth · CodeAlpaca일부

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

[output] | def remove_once(arr): freq_table = {} for num in arr: if num in freq_table.keys(): freq_table[num] += 1 else: freq_table[num] = 1 filtered_array = [] for num, freq in freq_table.items(): if freq > 1: filtered_array [instruction] | Write a Python program to remove the elements that occur only once from a given array. [input] | [1, 2, 2, 3, 3, 3, 4, 4]

[output] | func isEven(num: Int) -> Bool { return (num % 2) == 0 } [instruction] | Create a Swift function for checking if a number is even or odd. [input] |

[output] | def generate_tuples(n): tuples=[] for x in range (1,n+1): if n % x == 0: tuples.append((x,int(n/x))) return tuples [instruction] | Given a number n, generate a list of tuples of the form (x,n/x) where x divides n. [input] | n = 30

[output] | import json myDict = json.loads(myJSON) print(myDict) [instruction] | Given a JSON string, try to parse it into a Python dictionary. [input] | myJSON = '{"name":"John","age":30,"city":"New York"}'

[output] | def max_depth(node): if node is None: return 0 else: left_depth = max_depth(node.left) right_depth = max_depth(node.right) if left_depth > right_depth: return left_depth + 1 else: return right_depth + 1 [instruction] | Given a tree, write a program to find the maximum depth of the tree. [input] |

[output] | def store_data(table_name, data): conn = sqlite3.connect('database.db') cursor = conn.cursor() cursor.execute("""CREATE TABLE IF NOT EXISTS """ + table_name + "(data text)") insert_query = "INSERT INTO " + table_name + " VALUES (?)" cursor.execute(insert_query, (data,)) [instruction] | Create a program to input numerical data which can then be stored and retrieved into/from a database. [input] |

[output] | def xor(a, b): return bool(a) != bool(b) [instruction] | Write a function to return the logical XOR between two given boolean variables. [input] |

[output] | The complexity of the Fibonacci function from the previous question is O(2^n). [instruction] | What is the complexity of the function you wrote in Q6? [input] |

[output] | The best data structure to store the result of Q11 is a 2D array or matrix. This data structure can be used to efficiently retrieve the longest common subsequence of two strings. [instruction] | What data structure should you use to store the result of Q11 so that you can efficiently retrieve the desired result? [input] |

[output] | def appears_twice(lst, num): c = 0 for n in lst: if n == num: c += 1 if c > 2: return True else: return False [instruction] | Write a function that takes two input parameters, a list and a number, and returns true if the number occurs in the list more than twice. [input] |

[output] | def sort(array): length = len(array) for i in range(length): j = i while j > 0 and array[j-1] > array[j]: # Swap elements array[j], array[j-1] = array[j-1], array[j] j -= 1 return array [instruction] | Suggest an efficient algorithm for sorting the following list. [input] | [7, 1, 4, 8, 9, 2]

[output] | def Fibonacci(n): a = 0 b = 1 if n<0: print("Incorrect input") elif n==0: return a elif n==1: return b else: for i in range(2,n+1): c = a + b a = b b = c return b [instruction] | Given the following input, suggest a python code for computing the Fibonacci number for n. [input] |

[output] | def prime_numbers(n): numbers = list(range(2, n + 1)) for i in range(2, n+1): for j in range(i + 1, n+1): if j % i == 0: numbers[j - 2] = 0 return [number for number in numbers if number != 0] [instruction] | Suggest a method to print out a list of prime numbers below a given number n. [input] |

[output] | def remove_x(x, y): while x in y: y.remove(x) return y [instruction] | Generate a python code to remove all the occurrences of the element x from a list y. [input] |

[output] | def avg_list(lst): return sum(lst) / len(lst) [instruction] | Suggest a python code that returns the average of all the elements in a list. [input] |

[output] | def make_positive(lst): return [abs(x) for x in lst] [instruction] | Generate a code to make all the elements of a list positive. [input] |

[output] | def permutations(string): if len(string) == 0: return [] if len(string) == 1: return [string] l = [] for i in range(len(string)): m = string[i] rem_string = string[:i] + string[i+1:] for p in permutations(rem_string): l. [instruction] | Write a python code to generate permutations of an input string. [input] | "abc"

[output] | def histogram(lst): frequency = {} for item in lst: frequency[item] = frequency.get(item, 0) + 1 for item in frequency: print(item, '-->', '*' * frequency[item]) [instruction] | Design a code to generate a histogram from given data. [input] | [2, 3, 5, 6, 9]

[output] | let books = [ { name: 'Computer Programming Essentials', pages: 230 }, { name: 'Data Structures and Algorithms', pages: 180 }, { name: 'Artificial Intelligence Fundamentals', pages: 282 } ]; [instruction] | Create a JavaScript data structure to store a list of 3 books, where each book has a name and a page count. [input] | Book1: "Computer Programming Essentials", 230 pages Book2: "Data Structures and Algorithms", 180 pages Book3: "Artificial Intelligence Fundamentals", 282 pages

[output] | .italic { font-style: italic; } [instruction] | Create a CSS class to style text as italicized. [input] |

[output] | for item in list: print(item) [instruction] | Write a Python snippet that prints out each item in a given list. [input] | list = ["Apple", "Banana", "Cherry"]

[output] | $numbers = array(1, 2, 3, 4, 5); [instruction] | Write a PHP code to store an array of 5 numbers in a variable. [input] |

[output] | SELECT name, address FROM customers; [instruction] | Write an SQL query to return names and addresses of all customers. [input] |

[output] | for (int num : list) { if (num % 2 == 0) { System.out.println(num); } } [instruction] | Write a Java code that prints out all the even numbers in a given list. [input] | list = [2, 3, 4, 5, 6, 7, 8]

[output] | let encryptedString = CryptoJS.MD5(string).toString(); [instruction] | Use JavaScript to encrypt a given string using MD5 algorithm. [input] | string = "This is a test."

[output] | <table> <tr> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> </tr> </table> [instruction] | Create an HTML table containing 3 columns and 4 rows. [input] |

[output] | The methods used by the os module are: getcwd(), listdir(), mkdir(), rename(), chdir(), rmdir(), stat(), chmod(), remove(), chown(), and many more. [instruction] | List the methods used by the os module in python. [input] |

[output] | def reverse_list(head): curr = head prev = None while curr: next = curr.next curr.next = prev prev = curr curr = next head = prev return head [instruction] | Perform an in-place reversal of a linked list [input] |

[output] | <html> <head> <title>Data</title> </head> <body> <table> <thead> <th>Name</th> <th>Age</th> <th>Gender</th> </thead> <tbody> <tr> <td>Bob</td> <td>35</td> <td>Male</td> </tr> <tr> [instruction] | Create a HTML page displaying 3 columns of data [input] | Data: ["Name", "Age", "Gender"], ["Bob", 35, "Male"], ["John", 28, "Male"], ["Sarah", 39, "Female"]

[output] | #!/bin/bash echo "Hello, World!" [instruction] | Create a bash script that prints out a block of text that says, "Hello, World!". [input] |

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