← 목록

Synth · CodeAlpaca일부

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

[output] | # Function to randomly rearrange the elements of the given array import random def shuffle_array(nums): # Initialize a result array result = nums.copy() # Iterate over the array for i in range(len(nums)): # Generate a random index between 0 and the current index [instruction] | Randomly rearrange the elements of the given array. [input] | nums = [12, 23, 34, 45]

[output] | # Function to find the longest substring of given string with length greater than or equal to 2 without repeating letters def find_longest_substring(string): # Variable to store the starting index of the substring start_index = 0 # Hashset to store characters in string visited = [instruction] | Write a code to find the longest substring of given string with length greater than or equal to 2 without repeating letters. [input] | string = "abcdexyeffgghh"

[output] | import random user_agents = [ 'Mozilla/5.0 (Linux; Android 7.0; SM-G935P Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.83 Mobile Safari/537.36', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2', 'Mozilla [instruction] | Generate a random user agent string. [input] |

[output] | countries = { "United_Kingdom": 66_000_000, "United_States": 323_000_000 } [instruction] | Convert the Python list below to a nested dictionary of countries and their populations. [input] | List = [["United_Kingdom", 66_000_000],["United_States", 323_000_000]]

[output] | def replace_A(sentence): return sentence.replace('A','#') if __name__ == '__main__': print(replace_A(sentence)) [instruction] | Write a code to replace all the "A"s in the string with a "#". [input] | sentence = "Hello WAAorld"

[output] | import requests import json API_KEY = 'INSERT_YOUR_API_KEY_HERE' headers = { 'Accept': 'application/json' } def query_movie_databse(movie_title): url = 'http://www.omdbapi.com/?t="{}"&apikey={}'.format(movie_title, API_KEY) response = requests.get(url, headers=headers) data = json.l [instruction] | Write a code snippet to query the Intenet Movie Database for the release date of the movie "The Dark Knight". [input] |

[output] | import datetime def update_web_page_time_date(): # Get the current time and date current_time = datetime.datetime.now().strftime("%H:%M:%S %d-%m-%Y") # Update the content of the web page with open("index.html", "w") as fh: fh.write("<p>The current time and date is: {}<p>".f [instruction] | Write a code to update the content on the web page with current time and date. [input] |

[output] | def add(a,b): return a + b if __name__ == '__main__': print(add(a,b)) [instruction] | Write a code to add two numbers given as input. [input] | a = 1 b = 5

[output] | A parameter is a variable in a method definition. When a method is called, the arguments are the data you pass into the method's parameters. Parameters are specified after the method name, inside the parentheses. They are used to pass values to a method. An argument is the actual value of this varia [instruction] | Explain the difference between a parameter and an argument in Python. [input] |

[output] | The first 5 numbers in the Fibonacci sequence are 0, 1, 1, 2, 3. [instruction] | Find the first 5 numbers in the Fibonacci sequence. [input] |

[output] | The columns of the table are: fruit, price, and quantity. The rows of the table are: apple, banana, and mango. [instruction] | Given a pandas dataframe, identify the columns and rows of the table. [input] | import pandas as pd data = {'fruit': ['apple', 'banana', 'mango'], 'price': [2.99, 4.99, 5.99], 'quantity': [3, 5, 7]} df = pd.DataFrame(data)

[output] | This statement uses the sorted() function to sort the elements in the list 'input_list' in ascending order. The elements in the list will be compared using their default ordering and then sorted accordingly. The sorted list is returned and stored in a new list called 'sorted_list'. [instruction] | Explain the following Python statement. [input] | sorted_list = sorted(input_list)

[output] | def get_upper(string): """Return only uppercase characters from given string.""" return ''.join([c for c in string if c.isupper()]) [instruction] | Given a string of characters, write a function in Python that returns only the uppercase characters. [input] | "Hello, World!"

[output] | def remove_spaces(sentence): """Remove all spaces from a given sentence.""" return sentence.replace(" ", "") [instruction] | Write a function in Python that takes a sentence and removes all spaces. [input] | "Hello, World!"

[output] | def split_string(text): """Split a given string into a list of words.""" return text.split() [instruction] | Write a function in Python that takes a string and splits it into a list of words. [input] | "Hello, World!"

[output] | def product_of_elements(arr): """Return product of all elements in a given 2D array.""" product = 1 for row in arr: for ele in row: product *= ele return product [instruction] | Write a function in Python that takes a 2D array and returns the product of all elements in it. [input] | [[1, 2],[3, 4]]

[output] | def alternate_string(str1, str2): """Return a string with characters in alternating order from two given strings.""" result = "" for i in range(min(len(str1), len(str2))): result += str1[i] + str2[i] result += str1[i + 1:] + str2[i + 1:] return result [instruction] | Write a function in Python that takes two strings and returns a single string with the characters in alternating order. [input] | "Hello", "World!"

[output] | def is_prime(num): """Check if a number is a prime number.""" if num <= 1: return False for i in range(2,num): if num % i == 0: return False return True [instruction] | Write a function in Python that takes an integer and returns a boolean value specifying whether the number is a prime number or not. [input] | 9

[output] | def is_list_empty(list_str): """Check if a list is empty or not.""" return len(list_str) == 0 [instruction] | Write a function in Python that takes a list of strings and checks whether the list is empty or not. [input] | ["Hello", "World"]

[output] | def is_all_same_length(list_str): """Check if all strings in a list are of same length.""" return len(set(map(len, list_str))) == 1 [instruction] | Write a function in Python that takes a list of strings and checks if they are all the same length. [input] | ["Hello", "World"]

[output] | class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def push(self, data): node = Node(data) node.next = self.head self.head = node def pop(self): data = self.head.data self.head = self.head.next return data [instruction] | Write a Python class to implement a linked list. [input] |

[output] | def is_substring_present(string, sub_string): for i in range(len(string)): if string[i : (i + len(sub_string))] == sub_string: return True return False [instruction] | Write a function that determines if a given substring is present in a string or not. [input] |

[output] | def reverse_list(lst): for i in range(0, len(lst)//2): temp = lst[i] lst[i] = lst[len(lst)-1-i] lst[len(lst)-1-i] = temp return lst [instruction] | Edit the following code to return the elements in the reversed order. [input] | def reverse_list(lst): for i in range(0, len(lst)): temp = lst[i] lst[i] = lst[len(lst)-1-i] lst[len(lst)-1-i] = temp return lst

[output] | The data structure that can be used to convert the given list into a dictionary is a list of tuples. The tuples will comprise of the key and the value in the dictionary, e.g. ("apple", "pear"), (100, 0.25), (False, True). This can then be converted into a dictionary by using the dict() constructor. [instruction] | What data structure can be used to convert the following list into a dictionary? [input] | ["apple", "pear", "mango", 100, 0.25, False]

[output] | import string import random def generate_password(): char_set = string.ascii_uppercase + string.ascii_lowercase + string.digits return ''.join(random.sample(char_set, 8)) [instruction] | Generate a random password with at least 8 characters that contain both upper and lowercase letters and numbers. [input] |

[output] | def two_sum(num, lst): indices = [] for i in range(len(lst)): for j in range(i+1, len(lst)): if lst[i] + lst[j] == num: indices.append([i,j]) return indices [instruction] | Write a function that takes two arguments, a number and a list, and returns the indices in the list that add up the number. [input] |

[output] | def longest_sum_zero(arr): left = 0 max_len = 0 sum = 0 hash_map = dict() for right in range(len(arr)): sum += arr[right] if sum == 0: max_len = max(max_len, right - left + 1) if sum in hash_map: left = max(left, hash_map[sum] + 1) [instruction] | Given an array of integers, create a program that finds the longest subarray with a sum of 0. [input] |

[output] | def search(lst, val): for i in range(len(lst)): if lst[i] == val: return i return -1 [instruction] | Return the index of the value if it is present in the list or -1 if it is not present. [input] |

[output] | def count_consonants(sentence): consonants = 'bcdfghjklmnpqrstvwxyz' count = 0 for ch in sentence: if ch.lower() in consonants: count += 1 return count [instruction] | Count the number of characters in a sentence that begin with a consonant. [input] |

[output] | Adverb. [instruction] | Classify the following word as a noun, verb, adjective or adverb. [input] | Quickly

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