← 목록

Synth · CodeAlpaca일부

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

[output] | The time complexity of linear search in an unsorted array is O(n), where n is the number of elements in the array. This is because in linear search, the algorithm has to inspect each element in the array in order sequentially until it finds the desired element. As the size of the array increases, th [instruction] | What is the time complexity of linear search in an unsorted array? [input] |

[output] | import json json_object = { 'name': 'John', 'age': 20, 'location': 'New York' } data = json.loads(json_object) for key, value in data.items(): print(key + ": " + str(value)) [instruction] | Parse a given JSON object and output the contents in a tabular format [input] | json_object = { 'name': 'John', 'age': 20, 'location': 'New York' }

[output] | def longest_word(string): words = string.split(" ") longest_word_length = 0 for word in words: if len(word) > longest_word_length: longest_word_length = len(word) return longest_word_length [instruction] | Split a string into an array of words and return the length of the longest word. [input] |

[output] | text = "The sky is blue, the sea is blue. The grass is green." sentences = text.split(".") true_sentences = [] false_sentences = [] for sentence in sentences: if sentence.endswith("true"): true_sentences.append(sentence) else: false_sentences.append(sentence) print("True s [instruction] | Read a given text and classify each sentence as true or false. [input] | text = "The sky is blue, the sea is blue. The grass is green."

[output] | def prime_numbers(n): prime_nums = [] for num in range(2, n + 1): if num > 1: for i in range(2, num): if (num % i) == 0: break else: prime_nums.append(num) return prime_nums [instruction] | Create a function to generate a list of prime numbers between 2 and n. [input] |

[output] | def count_occurrences(string, character): count = 0 for i in range(len(string)): if string[i] == character: count += 1 return count [instruction] | Given a string and a character, write a program that counts the number of occurrences of the character in the string. [input] | string = 'Hello World!' character = 'l'

[output] | import random import string def generate_random_string(): rand_string = ''.join(random.choices(string.ascii_lowercase + string.digits, k=10)) return rand_string # testing random_string = generate_random_string( [instruction] | Generate a random string of length 10 consisting of letters and numbers. [input] |

[output] | db.users.find().limit(5) [instruction] | Compose a query using the MongoDB query language to return the first 5 documents in a collection named 'users'. [input] |

[output] | var items = []; items.push('Item 1'); items.push('Item 2'); [instruction] | Modify the below JavaScript code to add two items to an array. [input] | var items = [];

[output] | def search_tree(tree, value): # If the tree is empty if not tree: return False if value == tree.val: return True # If the given value is less than the tree's value # search left subtree elif value < tree.val: return search_tree(tree.left, value) [instruction] | Given a binary tree, write a code to search a given value in the tree. [input] |

[output] | num1 = 10 num2 = 20 result = num1 + num2 print(result) # Output 30 [instruction] | Run the following code in Python 3. [input] | num1 = 10 num2 = 20

[output] | class MinValue: def getMin(self, numList): minVal = numList[0] for i in numList: if i < minVal: minVal = i return minVal if __name__ == "__main__": obj = MinValue() numList = [12, 24, 72, 1, 4] print(obj.getMin(numList)) [instruction] | Write a class that has a method to return the smallest element in a given list of integers. [input] | [12, 24, 72, 1, 4]

[output] | def stringsplit(sentence): words=sentence.split(' ') return words if __name__ == "__main__": print(stringsplit('I am learning to code')) [instruction] | Create a function that takes a given sentence as input and outputs a list of all its words. [input] | Sentence: I am learning to code

[output] | def toUpperCase(words): upper_words=[] for word in words: upper_words.append(word.upper()) return upper_words if __name__ == "__main__": print(toUpperCase(['cat','dog','apple'])) [instruction] | Construct a code that takes a list of words as input and changes the case of each item in the list. [input] | [cat, dog, apple]

[output] | def find_unique(string): uniq_char = [] for i in string: if i not in uniq_char: uniq_char.append(i) return uniq_char print(find_unique("Geeksforgeeks")) [instruction] | Construct a code segment to find all unique characters in a given string. [input] | String: Geeksforgeeks

[output] | n = 35 for i in range(2, 35): while n % i == 0: print(i) n = n / i [instruction] | Create a loop that takes a given number as input and outputs its prime factors. [input] | Number: 35

[output] | d = {'a':2, 'b':3, 'c':4} def dictSum(d): total = 0 for key in d: total += d[key] return total if __name__ == "__main__": print(dictSum(d)) [instruction] | Write a code to sum all the values of the following dictionary. [input] | d = {'a':2, 'b':3, 'c':4}

[output] | def replace_with_next_char(string): output = "" for char in string: output += chr(ord(char) + 1) return output [instruction] | Generate python code to replace each character in a string with the next character in the alphabet. [input] |

[output] | You can use a for loop to traverse a dictionary by iterating over the dictionary's keys or key-value pairs. For example, you can loop through all the keys of a dictionary like this: dictionary = { 'a':1, 'b':2, 'c':3 } for key in dictionary: print(key) Or you can loop through all the key-v [instruction] | How can you use a for loop to traverse a dictionary? [input] |

[output] | A dictionary is a suitable data structure for keeping track of the list of items purchased by each customer. The key would be the customer name and the value would be a list of items purchased by the customer. [instruction] | What data structure could you use to keep track of the list of items purchased by each customer? [input] |

[output] | The fadeIn() function in jQuery is used to gradually increase the opacity of an element from hidden to visible, in a specified duration. The function works by adjusting the CSS property for opacity for the element, from 0 to 1, over a specified duration of time. [instruction] | How does the fadeIn() function work in jQuery? [input] |

[output] | Please enter your name: [instruction] | Write a prompt message that asks the user to enter their name. [input] |

[output] | A web page typically consists of the following components: a header, content area, sidebar, footer, and navigation menu. The header typically contains the page title and logo or navigation links. The content area displays the main information on the page. The sidebar typically contains additional li [instruction] | Describe the main components of a web page. [input] |

[output] | #!/bin/bash day=$(date +%A) echo "Today is $day" [instruction] | Write a Bash script that prints out the day of the week. [input] |

[output] | {"name": "shivam"} [instruction] | Ensure the string is formatted correctly according to JSON standard. [input] | {"name": shivam"

[output] | <div id="chartContainer"></div> <script> var chart = new CanvasJS.Chart("chartContainer", { //Options }); chart.render(); </script> [instruction] | Display a chart on the page to show the data. [input] |

[output] | function mergeTrees(t1, t2) { // exit case, if one of the trees are null if (!t1 || !t2) return t1 || t2 //Otherwise, merge the new node values from both trees let t3 = new TreeNode(t1.val + t2.val); // recursively traverse both trees to build up the result t3.left = mergeT [instruction] | Merge two binary trees t1 and t2 into a new binary tree. [input] | t1 = 1 / \ 4 5 / \ 8 9 t2 = 2 / \ 7 8 / 9

[output] | let fib = [0, 1]; while (fib.length < 10) { fib.push(fib[fib.length - 1] + fib[fib.length - 2]); } console.log(fib); // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] [instruction] | Generate an array of the first 10 Fibonacci numbers using any programming language. [input] |

[output] | def get_total(my_dict): total = 0 for item in my_dict.values(): total += item['price'] * item['quantity'] return total print(get_total(my_dict)) // 90 [instruction] | Write a function in Python which takes the information from the following dictionary and prints out the total price of all the items in it. §§ 1020 [input] | my_dict = { 'item1': {'price': 20, 'quantity': 5}, 'item2': {'price': 10, 'quantity': 3}, }

[output] | def isSetPalindrome(s): n = len(s) for i in range(int(n/2)): if s[i] != s[n - i - 1]: return False return True §§ 1060 print(isSetPalindrome(s)) // True [instruction] | Given a set of strings s, find an algorithm to determine if the set is a palindrome. [input] | s = {"b", "c", "a", "a", "c", "b"}

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