← 목록

Synth · CodeAlpaca일부

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

[output] | def equal(list1, list2): if len(list1) != len(list2): return False for i in range(len(list1)): if list1[i] != list2[i]: return False return True [instruction] | Write a function to check whether two lists are equal. [input] | list1=[1,2,3,4,5] list2=[1,2,3,4,5]

[output] | def find_most_frequent_element(arr): d = {} for num in arr: if num in d: d[num] += 1 else: d[num] = 1 max_freq = 0 most_frequent_element = None for num in d: if d[num] > max_freq: max_freq = d[num] most [instruction] | Implement a function to return the element that appears most frequently in a list. [input] | [5,5,5,5,6,6,7,7,7]

[output] | type(x) # List [instruction] | Identify the type of a variable in a Python program. [input] | x = [1, 2, 3]

[output] | x = "Hello world" [instruction] | Choose the correct output for following code snippet. [input] | x = "hello world" y = x y[0] = "H"

[output] | def largest_param(param1, param2): if param1 > param2: return param1 else: return param2 [instruction] | Create a program that takes two parameters and print out the result of the larger one. [input] | param1 = 20 param2 = 50

[output] | def join_strings(str1, str2, separator): return str1 + separator + str2 [instruction] | Take two strings and a separator as inputs and join the two strings using the separator and output the resulting string. [input] | str1="Hello" str2="World" separator="-"

[output] | def sort_by_score(lst): lst.sort(key=lambda item: item['score']) return lst [instruction] | Write a Python program to sort the given list of dictionary elements by the score value [input] | lst = [{"score":1},{"score":5},{"score":8}]

[output] | def min(a, b, c): if a < b and a < c: return a elif b < a and b < c: return b else: return c [instruction] | Edit the code below to calculate minimum of 3 numbers. [input] | def min(a, b): if a < b: return a else: return b

[output] | def convert_to_tuple(lst): tup = [(x['name'], x['age']) for x in lst] return tuple(tup) [instruction] | Convert the given list of dictionaries to a tuple of tuples. [input] | lst = [{"name":"John", "age":21}, {"name":"Bill", "age":30}]

[output] | def remove_excess_lst(lst): # Count the frequency of each element in the list cnt = Counter(lst) # Return the list with elements appearing more than 3 times removed return list(filter(lambda x: cnt[x] <= 3, lst)) [instruction] | Code a solution to remove any element from given list if it appears more than 3 times. [input] | [1,2,3,1,1,1,2]

[output] | for (let i = 0; i <= 12; i++) { console.log(i); } [instruction] | Create a loop that will print out numbers from 0 to 12. [input] |

[output] | function maxOverlapping(arr) { let max = 0; let curr = 0; const timeline = {}; for (let i = 0; i < arr.length; i++) { const start = arr[i][0]; const end = arr[i][1]; timeline[start] = (timeline[start] || 0) + 1; timeline[end] = (timeline[end] || 0) - 1; } for (const key i [instruction] | Develop a program that finds the maximum number of overlapping events within a given time period. [input] | [[1, 7], [2, 5], [3, 6], [8, 10]]

[output] | function charCount(str) { let result = {}; for (let i = 0; i < str.length; i++) { let char = str[i].toLowerCase(); result[char] = (result[char] || 0) + 1; } return result; } console.log(charCount('Hello World')); // output: {h: 1, e: 1, l: 3, o: 2, w: 1, r: 1, d: 1} [instruction] | Create a program that takes a string and returns an object with the count of all the characters in the string. [input] | "Hello World"

[output] | let chessBoard = [["BR", "BK", "BB", "BR"]]; [instruction] | Convert the following chess board into a 2D array in JavaScript. [input] | +---+ |BR | |BK | | BB| |BR | +---+

[output] | name = "John" age = 35 [instruction] | Create a variables in Python to store the following information. [input] | Name: John, Age: 35

[output] | <h2>Welcome</h2> [instruction] | Edit the following HTML to create a heading with the title "Welcome". [input] | <h2>Hello World</h2>

[output] | import random # Print random integer print(random.randint(0, 5)) [instruction] | Write a Python program to print a random integer between 0 and 5. [input] |

[output] | function validateEmail(email) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); } [instruction] | Create a validation rule to check if an email address is valid for an input field in JavaScript. [input] |

[output] | int time = 10; switch (time) { case time < 12: System.out.println("Good morning"); break; case time < 17: System.out.println("Good afternoon"); break; case time >= 17: System.out.println("Good evening"); break; } [instruction] | Rewrite the following Java code using a switch statement instead of if/else. [input] | int time = 10; if (time < 12) { System.out.println("Good morning"); } else if (time < 17) { System.out.println("Good afternoon"); } else { System.out.println("Good evening"); }

[output] | function isAnagram(string1, string2) { const s1 = string1.split('').sort().join(''); const s2 = string2.split('').sort().join(''); return s1 === s2; } [instruction] | Write a function that takes two strings and determines whether one string is an anagram of the other. [input] | string1 = 'listen'; string2 = 'silent'

[output] | int number1 = 5; int number2 = 10; int sum = number1 + number2; [instruction] | Write a C# code snippet to add 2 numbers. [input] |

[output] | import random random_list = [random.randint(0, 10) for _ in range(5)] [instruction] | Generate a random 5-element list of integers between 0 and 10. [input] |

[output] | class Box: def __init__(self, width, length, height): self.width = width self.length = length self.height = height def calculate_volume(self): return self.width * self.length * self.height [instruction] | Write a class definition for a Box class. [input] |

[output] | python helloworld.py [instruction] | Run the program located in 'helloworld.py' [input] |

[output] | import pandas as pd data = pd.read_csv('data.csv') df = pd.DataFrame(data) [instruction] | Convert this CSV data into a Pandas DataFrame. [input] | name,age John,20 James,31

[output] | The lowest integer that can not be represented as the sum of two prime numbers is 45. [instruction] | Find the lowest integer that can not be represented as the sum of two prime numbers. [input] |

[output] | A hash table (or a dictionary in Python) is the best data structure to store key-value pairs. [instruction] | What data structure would be best to store key-value pairs? [input] |

[output] | def moveZeroes(nums): zeros = 0 for i in range(len(nums)): if nums[i] == 0: zeros += 1 else: nums[i-zeros] = nums[i] nums[len(nums)-zeros:] = [0] * zeros [instruction] | Write a function to move all zeros in an array to the end. [input] | [1, 2, 0, 3, 4, 0, 5]

[output] | new_list = [i * 5 for i in [1, 2, 3, 4, 5]] [instruction] | Create a new list filled with the same values as the existing list but with the values multiplied by 5. [input] | [1, 2, 3, 4, 5]

[output] | def get_mismatches(arr1, arr2): mismatches = 0 if len(arr1) != len(arr2): return -1 for i in range(len(arr1)): if arr1[i] != arr2[i]: mismatches += 1 return mismatches [instruction] | Write a method to compare two unsorted arrays of integers and find the number of mismatches. [input] | [1, 3, 2, 5], [2, 4, 1, 5]

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