← 목록

Synth · CodeAlpaca일부

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

[output] | function doubleNumber(num) { return num * 2; } [instruction] | Re-write this Python code as a JavaScript function. [input] | def double_number(num): return num * 2

[output] | The most suitable data structure for this use case is an object, as it is capable of storing multiple values of various types. [instruction] | Determine the type of data structure that is most suitable for the given case. [input] | Use case: You need to store multiple formats of information like a person's name (string), age (integer) and pets (array) in a data structure.

[output] | a:link { color: blue; } a:visited { color: red; } [instruction] | Create a CSS style that changes the color of links to red when visited. [input] |

[output] | The %i in Python is a special format specifier used to format integer numbers. When used in a format string, it will convert the number to an integer and insert it into the output string. This can be used to easily format numbers when printing output. [instruction] | Explain the purpose of the %i in a Python format string. [input] |

[output] | console.log("Hello World!"); [instruction] | Change the following code snippet to use a different method to display the alert. [input] | alert("Hello World!");

[output] | from pyspark.sql import SparkSession # Create SparkSession object spark = SparkSession.builder.getOrCreate() # Create Spark DataFrame using Pandas df spark_df = spark.createDataFrame(df) [instruction] | Create an instance of an Apache Spark DataFrame using an existing Pandas dataframe. [input] | import pandas as pd df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})

[output] | import numpy as np arr = np.array([[1,2,3],[4,5,6]]) # Get the sum of all elements in the array total_sum = np.sum(arr) # Print the sum print(total_sum) [instruction] | Compute the sum of all elements in a numpy array. [input] | import numpy as np arr = np.array([[1,2,3],[4,5,6]])

[output] | import html # Parse the string parsed_string = html.unescape(html_string) # Extract the text content text_content = parsed_string.split('>')[-1] # Print the content print(text_content) [instruction] | Parse a string containing HTML markups and extract the text content. [input] | html_string = '<html><body><h1>Sample HTML String</h1>Hello there!</body></html>'

[output] | def get_index_of_first_diff(string1, string2): # Get the length of the strings len_1 = len(string1) len_2 = len(string2) # Get the length of the shorter string len_shorter = min(len_1, len_2) # Compare the two strings character by character for i in range(len_shorter): [instruction] | Compare two strings and return the index of the first character that is unequal in the two strings. [input] | string1 = "Hello world!" string2 = "Howdy world!"

[output] | def linear_search(nums, target_num): # Get the length of the array len_nums = len(nums) # Loop through the array to find the index of the target number for i in range(len_nums): if nums[i] == target_num: # Return the index of the target number return [instruction] | Perform a linear search on an array of 10 numbers and return the index for the target number. [input] | nums = [2, 8, -4, 1, 0, 5, 3, 9, 6, 10] target_num = 8

[output] | import numpy as np # Convert the array of tuples into an array of complex numbers complex_arr = np.array(tuple_array, dtype=complex) # Print the complex array print(complex_arr) [instruction] | Convert an array of tuples of 2 numbers into an array of complex numbers. [input] | tuple_array = [(3,4), (5,6), (7,8)]

[output] | # Create a dictionary of emails and corresponding info email_dict = {email[0]: email[1:] for email in my_list} # Print the dictionary print(email_dict) [instruction] | Given a list of emails and corresponding info, write a code to keep only the emails and transform the list into a dictionary of emails and corresponding info. [input] | my_list = [('john@example.com', 'John Smith', '27'), ('sarah@example.com', 'Sarah Jane', '31'), ('paul@example.com', 'Paul Walker', '45')]

[output] | # Create a list of unique elements from given list unique_nums = list(set(nums)) # Print the list print(unique_nums) [instruction] | Create a list of unique elements from a list of numbers. [input] | nums = [1, 1, 2, 3, 3, 4, 4, 5, 6]

[output] | from datetime import datetime import re # Parse the date string date = datetime.strptime(date_string, '%d %B %Y') # Convert the date to ISO 8601 format iso_8601 = date.strftime("%Y-%m-%d") # Print the ISO 8601 formatted date print(iso_8601) [instruction] | Write a Python program to parse a date string and display the date in ISO 8601 format. [input] | date_string = '21 May 2021'

[output] | SELECT MAX(age) AS maximum, MIN(age) AS minimum FROM Users; [instruction] | Write a SQL query to retrieve the max and min values from a field. [input] | table_name = 'Users' column_name = 'age'

[output] | for item in list_to_traverse: print(item) [instruction] | Create a for loop to traverse a list and print each element in the list in sequence. [input] | list_to_traverse = [1,2,3,4,5]

[output] | # Create an empty string new_string = "" # Iterate over the even indices for i in range(0, len(my_string), 2): new_string += my_string[i] # Print the new string print(new_string) # prints 'acegi' [instruction] | Using the input string, create a new string that contains all the characters in even indices. [input] | my_string = "abcdefghi"

[output] | try: with open("myfile.txt") as f: for line in f: print(line) except: print("An exception has been thrown") [instruction] | Add a try-catch block around the code example that catches an exception if it is thrown. [input] | with open("myfile.txt") as f: for line in f: print(line)

[output] | public class ArraySizeDiff { public static void main(String[] args) { int[] arr1 = {1, 2, 3, 4, 5}; int[] arr2 = {1, 2, 3}; int diff = arr1.length - arr2.length; System.out.println("Difference in number of elements between the two arrays is: " + diff); } } [instruction] | Write a Java program that creates two arrays and prints out the difference in number of elements between them. [input] | int[] arr1 = {1, 2, 3, 4, 5}; int[] arr2 = {1, 2, 3};

[output] | new_list = [] for string in my_list: new_list.append(string.capitalize()) print(new_list) # prints ['Hello', 'World', 'How', 'Are', 'You?'] [instruction] | Using the input, create a new list of strings where all strings in the new list have an uppercase first letter. [input] | my_list = ["hello", "world", "how", "are", "you?"]

[output] | div { width: 100px; } [instruction] | Create a CSS rule to set the div width to 100px. [input] |

[output] | ^\d{3,}$ [instruction] | Create a regex pattern to match strings having at least 3 digits. [input] |

[output] | if num % 2 == 0 puts "The number is even" end [instruction] | Write a Ruby statement to check if the given number is even. [input] | num = 6

[output] | if num % 2 == 0 puts "The number is even" else puts "The number is odd" end [instruction] | Using the input, classify whether the number is even or odd. [input] | num = 5

[output] | class Point { constructor(x, y) { this.x = x; this.y = y; } distance(other) { let dx = this.x - other.x; let dy = this.y - other.y; return Math.sqrt(dx * dx + dy * dy); } } [instruction] | Create an object-oriented JavaScript class to represent a point in two-dimensional space. [input] |

[output] | SELECT TOP 5 customers.* FROM customers WHERE customers.address LIKE '%USA%' ORDER BY customers.name [instruction] | Create a SQL query to select the top 5 customers whose address is in the USA. [input] |

[output] | int result = (int)Math.pow(3, 3) + 11 * (3 + 3); // result = 144 [instruction] | Calculate the following expression using Java: (3^3+11) × (3+3) [input] |

[output] | <html> <head> <title> Title of page </title> </head> <body> <h1> Header title </h1> <p> This is a sample content of a web page. </p> </body> </html> [instruction] | Complete the following HTML template with appropriate tags: [input] | <html> <head> </head> <body> </body> </html>

[output] | One technique to detect plagiarism in programming assignments is to compute the similarity between submissions and reference solutions. This can be done by extracting the key pieces of code from submissions, such as functions and loops, and then comparing them against the reference solution. If the [instruction] | Suggest a technique to detect plagiarism in programming assignments. [input] |

[output] | def find_longest_substring(s): max_length = 0 start = 0 usedChar = {} for i in range(len(s)): if s[i] in usedChar and start <= usedChar[s[i]]: start = usedChar[s[i]] + 1 else: max_length = max(max_length, i - start + 1) usedChar[s[i]] = i return max_length i [instruction] | Create a python program that takes a string as input and prints the length of the longest substring without repeatingcharacters. [input] | "abcabcbb"

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