← 목록

Synth · CodeAlpaca일부

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

[output] | SELECT * FROM students WHERE state = 'Idaho'; [instruction] | Suggest a MySQL query that retrieves all students from the "Idaho" state. [input] |

[output] | $string = "Hello World!"; for ($char of str_split($string)) { echo $char . "\n"; } [instruction] | Rewrite the following php code in a more efficient manner [input] | $string = "Hello World!"; for ($i = 0; $i < strlen($string); $i++){ echo $string[$i] . "\n"; }

[output] | The main difference between a switch statement and an if-else statement in C++ is that the switch statement is used for multiple-branch control of the program, while the if-else statement is used for dual-branch control. The switch statement tests the value of a variable from a given set of matches [instruction] | Describe the main difference between a switch statement and an if-else statement in C++ [input] |

[output] | def pascal(n): # An auxiliary array to store # generated pascal triangle values arr =[[0 for x in range(n)] for x in range(n)] # Iterate through every line and # print integer(s) in it for line in range(0, n): # Every line has number of [instruction] | Generate a code to form a Pascal Triangle with the given input. [input] | n = 5

[output] | import json import xmltodict # Load JSON data data_str = ''' { "employees":{ "employee":[ { "name":"John Smith", "id":123 }, { "name":"Jane Doe", "id":456 } ] } } ''' data_dict = [instruction] | Write code to convert JSON to XML with provided attribute. [input] | { "employees":{ "employee":[ { "name":"John Smith", "id":123 }, { "name":"Jane Doe", "id":456 } ] } } Attribute: "person"

[output] | import requests url = 'https://www.example.com/' # Make an API call and store the response res = requests.get(url) # Retrieve the data data = res.text [instruction] | Retrieve the data in the given URL. [input] | URL: https://www.example.com/

[output] | from bs4 import BeautifulSoup html_data = ''' <li><a href="/home">Home</a></li> <li><a href="/about">About</a></li> ''' soup = BeautifulSoup(html_data, 'lxml') # Get content from <a> tags links = soup.find_all('a') # Retrieve the values from each link for link in links: print(link.get('hre [instruction] | Parse the following HTML content and retrieve the values from the key elements. [input] | <li><a href="/home">Home</a></li> <li><a href="/about">About</a></li>

[output] | SELECT * FROM People WHERE Age > 25; [instruction] | Write a statement to select the rows from the following table that have age>25. [input] | Table: People Name | Age | Location John | 21 | New York Jane | 33 | London

[output] | # Create a linked list class Node: def __init__(self, data): self.data = data self.next = None # Function to convert linked list to array def list_to_array(head): arr = [] if head is None: return arr cur = head while cur is not None: arr.appe [instruction] | Change the following linked list into an array. [input] | Linked list: 1->3->5->7->9

[output] | import json # Load JSON data data_str = ''' { "name": "John", "age": 42, "location": "New York" } ''' data_dict = json.loads(data_str) # Get the value of the given key name = data_dict.get('name') # John [instruction] | Write a Python program that parses a JSON object and returns only the values of a specific key. [input] | JSON object: { "name": "John", "age": 42, "location": "New York" } Key: "name"

[output] | # Swapping two numbers using a temporary variable a, b = 10, 20 temp = a a = b b = temp print('a:', a) print('b:', b) [instruction] | Write a code that swaps the two numbers using a temporary variable. [input] | a = 10, b = 20

[output] | # Create the string from the list my_string = ' '.join(map(str, my_list)) # Print the string print(my_string) # Hello world this is a test [instruction] | Change the following list of strings into a single combined string. [input] | my_list = ["Hello", "world", "this", "is", "a", "test"]

[output] | def transpose_matrix(matrix): """Function to transpose 2d list matrix""" row = len(matrix) col = len(matrix[0]) transpose = [[0 for j in range(row)] for i in range(col)] for i in range(row): for j in range(col): transpose[j][i] = matrix[i][j] [instruction] | Using the input as a guide, write code that prints out a copy of the 2d matrix with its elements transposed. [input] | matrix = [[1,2,3],[4,5,6],[7,8,9]]

[output] | def odd_numbers_list(input_data): """Function to create a list that preserves the order of the original input and contains only the odd numbers from it""" output_list = [] for el in input_data: if el % 2 != 0: output_list.append(el) return output_list if __nam [instruction] | Write a code to create a list that preserves the order of the original input and contains only the odd numbers from it? [input] | [1,2,3,4,5,6,7,8,9]

[output] | def find_max_of_three(a, b, c): """Function that takes an integer parameter and find the maximum of the three numbers with the help of ternary operator""" max_value = a if a > b and a > c else (b if b > a and b > c else c) return max_value if __name__ == '__main__': a = 1 b = 5 [instruction] | Write a function that takes an integer parameter and find the maximum of the three numbers with the help of ternary operator. [input] |

[output] | def find_median(A, B): """Function to find median of two sorted arrays""" m = len(A) n = len(B) if m > n: A,B,m,n = B,A,n,m imin, imax, half_len = 0, m , (m+n+1) // 2 while imin <= imax: i = (imin+imax) // 2 j = half_len -i if i < m and B[j-1] [instruction] | Write a python code to find median of two sorted arrays. [input] | A = [1,4,6,7]B = [3,5,8,9]

[output] | # Start of code i = 1 while i<=10: print(i) i += 1 # End of code [instruction] | Fix the code so that the loop terminates after 10 iterations. [input] | # Start of code i = 1 while i<100: print(i) i += 1 # End of code

[output] | The statements that are erroneous or have logical errors are: 1) There is no colon (:) after the 'if' and 'elif' statements 2) There is no colon (:) after the 'else' statement. 3) The parentheses after 'print' are unnecessary. [instruction] | Identify all the statements that are erroneous or have logical errors. [input] | a = 2 b = 1 if a > b print("a is greater than b") elif a == b print("a is equal to b") else print("b is greater than a")

[output] | def get_alphabet_frequencies(sentence): """Function to generate a dictionary that contains the frequencies of all English alphabets in a given sentence""" alphabet_freq = dict() for el in sentence: if el.isalpha(): el = el.lower() if el in alphabet_freq: [instruction] | Write a code to generate a dictionary that contains the frequencies of all English alphabets in a given sentence. [input] | Sentence: The brain is a powerful tool

[output] | my_output = [item*item for item in my_list] [instruction] | Generate a list comprehension to replicate the given code example. [input] | my_list = [1, 2, 3, 4, 5] my_output = [] for item in my_list: my_output.append(item*item)

[output] | for order_num in sorted(order_num): print(order_num) # Output: # 1530 # 3489 # 4792 # 7421 [instruction] | Construct a for loop to print a list of order numbers in ascending order. [input] | order_num = [1530, 3489, 7421, 4792]

[output] | prices_dict = dict(zip(items, prices)) # prices_dict = {'book': 10, 'pen': 2, 'chair': 5} [instruction] | Create a dictionary of items with the corresponding price in Python. [input] | items = ['book', 'pen', 'chair'] prices = [10, 2, 5]

[output] | for (let i = 0; i < my_array.length; i++) { console.log(my_array[i]); } # Output: # 1 # 2 # 3 [instruction] | Generate a JavaScript code to console log the elements in a given array for each iteration. [input] | let my_array = [1, 2, 3]

[output] | SELECT * FROM orders WHERE order_num >= 1000; [instruction] | Construct a SQL query to select the orders with order_num >= 1000. [input] |

[output] | add = lambda num1, num2: num1 + num2 print(add(num1, num2)) # Output: 35 [instruction] | Generate a Python code to add two numbers using a lambda expression. [input] | num1 = 10 num2 = 25

[output] | for i in sorted(my_array, reverse=True): print(i) # Output: # 7 # 5 # 4 # 3 # 1 [instruction] | Construct a for loop in Python to print the array in descending order. [input] | my_array = [4, 3, 5, 7, 1]

[output] | function commaFormatting(num) { return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); } console.log(commaFormatting(num)) // Output: 1,000 [instruction] | Create a JavaScript function to format a given number with commas. [input] | num = 1000

[output] | regex = r"\w*ed\b" [instruction] | Write a Regex expression to search for all words ending with "ed" [input] |

[output] | # Counting frequencies counts = dict() words = s.split(' ') for word in words: if word in counts: counts[word] += 1 else: counts[word] = 1 # Getting the kth most frequent element kth_most_frequent = sorted(counts, key = counts.get, reverse = True)[k-1] print(kth [instruction] | Given a string s and an integer k, write a code to find the kth most frequent element in the string [input] | String s: "hello world hello" Integer k: 2

[output] | from datetime import datetime, timezone def local_time(gmt_time): utc_time = datetime.fromisoformat(gmt_time.replace("Z", "+00:00")) local_time = utc_time.astimezone() return local_time.isoformat() [instruction] | Create a program to convert a given time in GMT form to local time. [input] |

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