[output] | def surface_area_cylinder(radius, height): pi = 3.14 return 2*pi*radius*(radius + height) [instruction] | Create a Python script that calculates the surface area of a cylinder. [input] |
[output] | requests = [] for i in range(100000000): requests.append(i) # use list comprehension to generate the list in one line requests = [i for i in range(100000000)] [instruction] | Suggest improvements to the following code to optimize its performance. [input] | requests = [] for i in range(100000000): requests.append(i)
[output] | A better data structure to store a large amount of data in a way that querying is fast would be a Hash Table. Hash Tables store data in an associative array, allowing for fast searches and retrieval of data. [instruction] | Suggest a better data structure that can be used to store a large amount of data in a way that querying data is fast. [input] |
[output] | mylist = [1, 2, 3, 4, 5] del mylist[3] print(mylist) [instruction] | Write a code to delete the 4th element from the list. [input] | mylist = [1, 2, 3, 4, 5]
[output] | word = "hello" word = '$' + word + '$' print(word) [instruction] | Write a code to append a character at the start and end of a given string. [input] | word = "hello"
[output] | The maximum number of nodes in a height-balanced binary tree of height 4 is 15. This can be determined by using the formula 2^(h+1) - 1. [instruction] | Determine the maximum number of nodes in a height-balanced binary tree of height h. [input] | h = 4
[output] | The time complexity of inserting a value into a singly linked list is O(1), as it is a constant time operation. [instruction] | What is the time complexity of inserting a value into a singly linked list? [input] |
[output] | Heapify is one of the methods to convert a given array into a min-heap. This process involves repeatedly swapping the root element with its smallest child (if it exists) to satisfy the min-heap property. [instruction] | Suggest a method to convert a given array into a min-heap. [input] |
[output] | A URL can be parsed into its individual components by using string manipulation and built-in methods such as ``split()`` and ``replace()``. The components generally include the protocol, host name, path, query string and fragment. [instruction] | How would you parse a URL into its individual components? [input] |
[output] | def product_list(numbers): # Initialize the result result = 1 # Iterate over the input numbers for x in numbers: result *= x # Return the result return result [instruction] | Modify the following code to return the product of all numbers in a given list. [input] | def product_list(numbers): # Initialize the result result = 1 # Iterate over the input numbers for x in numbers: result = result * x # Return the result return result
[output] | a = 3 b = 'aa' b = b * a print(b) [instruction] | Change the following code to make it easier to read [input] | a=3;b='aa';b*=a;print(b)
[output] | The parameters x, y and z are used in this function to represent arbitrary values. They can represent integers, floats, strings, lists, dictionaries, objects, etc. Depending on the specific implementation of this function, the parameters can take any meaning, representing any value. For example, it [instruction] | Understand the parameters used in the following code and explain their purpose. [input] | def doSomething(x, y, z): pass
[output] | def find_target(nums, target): for i, num in enumerate(nums): if num == target: return i return -1 if __name__ == '__main__': nums = [2, 3, 5, 7] target = 5 index = -1 for i in range(0, len(nums)): if nums[i] == target: index = i [instruction] | Change the following code to reduce its running time [input] | for i in range(0, len(nums)): if nums[i] == target: return i
[output] | def print_words_with_count(sentence): word_count = {} words = sentence.split() for word in words: if word not in word_count: word_count[word] = 1 else: word_count[word] += 1 for word, count in word_count.items(): print("Word: %s Count: %d" % (word, count)) [instruction] | Can you modify the program so that it prints out all words in the sentence along with their count? [input] | "The quick brown fox jumped over the lazy dog."
[output] | def FibonacciSeries(n): if n <= 0: return [0] elif n == 1: return [0,1] else: series = [0,1] for i in range(2, n): curr_num = series[i-1] + series[i-2] series.append(curr_num) return series [instruction] | Modify the program to support calculating Fibonacci numbers up to the nth number. [input] |
[output] | def reverse_and_trim(s): s = s.strip() s = s.replace(" ", "") return s[::-1] [instruction] | Generate a program to reverse a string and remove all the white spaces from the string. [input] | " The quick brown fox jumped over the lazy dog. "
[output] | SELECT name FROM Employee; [instruction] | Generate a SQL query for finding the names of all employees in the company. [input] |
[output] | <table> <tr> <th>Name</th> <th>Age</th> </tr> <tr style="background-color: lightgrey;"> <td>John</td> <td>30</td> </tr> <tr> <td>Anna</td> <td>20</td> </tr> <tr style="background-color: lightgrey;"> <td>Mark</td> <td>25</td> </tr> <tr> <td>Amy</t [instruction] | Edit this HTML code to highlight odd rows of this table. [input] | <table> <tr> <th>Name</th> <th>Age</th> </tr> <tr> <td>John</td> <td>30</td> </tr> <tr> <td>Anna</td> <td>20</td> </tr> <tr> <td>Mark</td> <td>25</td> </tr> <tr> <td>Amy</td> <td>28</td> </tr> </table>
[output] | def capitalize_first_letter(text): words = text.split(' ') capitalized_words = [word[0].upper() + word[1:] for word in words] return ' '.join(capitalized_words) text = "This is a sample sentence." capitalized_text = capitalize_first_letter(text) print(capitalized_text) # Output: This Is [instruction] | Generate a code to capitalize the first letter of each word of a given sentence. [input] | text = "This is a sample sentence."
[output] | import pyodbc conn = pyodbc.connect( DRIVER='Amazon Redshift ODBC Driver', SERVER=<your instance URL>, PORT=<port number>, DATABASE=<database name>, UID=<username>, PWD=<password>) cursor = conn.cursor() query = <your SQL query> cursor.execute(query) data = cursor.fetchall( [instruction] | Create a Tableau script to retrieve data from an Amazon RDS instance. [input] |
[output] | #include<iostream> using namespace std; // Function to sort an array in ascending order void asc_sort(int arr[], int n) { int temp; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (arr[i] > arr[j]) { temp = arr[i]; arr[i] = arr[j]; [instruction] | Write a C++ program to sort an array in ascending and descending order. [input] | int arr[] = {2, 3, 1, 5, 4}
[output] | def insert(self,val): if not self.root: self.root = Node(val) else: current = self.root while True: if val < current.val: if current.left: current = current.left else: current.left = Node(val) break elif val > current.val: if current.right: c [instruction] | Implement a function to insert an element into a binary search tree. [input] | tree = 5 / \ 2 8
[output] | def countOccurrence(txt, pattern): count = 0 for i in range(len(txt)): if txt[i:i+len(pattern)] == pattern: count += 1 return count [instruction] | Write code to count the number of times a given pattern has occured in a given string. [input] | Text: “This is a test string to practice coding. This string contains the pattern “is”
[output] | celsius = 52 fahrenheit = (celsius * 9/5) + 32 puts "The temperature in fahrenheit is #{fahrenheit} degrees" [instruction] | Write a Ruby script that converts a given number in degree Celsius to Fahrenheit. [input] | 52
[output] | false [instruction] | You need to read a text and detect if the sentence contains any curse words or not. Output true if there is a curse word, output false if there is not. [input] | When I saw the movie, I was so angry that I wanted to scream.
[output] | public class Sum { public static int getSum(int[] arr) { int sum = 0; for(int i=0; i < arr.length; i++) sum += arr[i]; return sum; } } [instruction] | Create a function in Java that takes in an array of numbers and calculates the sum of the elements. [input] | [1, 2, 3, 4, 5]
[output] | int count_positive(int arr[], int size) { int count = 0; for (int i = 0; i < size; i++) if (arr[i] > 0) count++; return count; } int arr[] = {-1,-43,2,6,0,18}; int n = sizeof(arr)/sizeof(arr[0]); count_positive(arr, n); [instruction] | You have to read a set of numbers and report the number of positive numbers. [input] | [-1, -43, 2, 6, 0, 18]
[output] | import random for i in range(10): print(random.randint(0, 1000)) [instruction] | Generate random numbers 0 to 1000. [input] |
[output] | import re string1 = "Hello World" string2 = "Hello*World" pattern = re.compile(string2.replace('*', '.')) match = pattern.search(string1) if match: print('Matched!') [instruction] | Match the strings "string1" and "string2" using regex. [input] | string1="Hello World" string2="Hello*World"
[output] | class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def append(self, data): new_node = Node(data) if self.head == None: self.head = new_node else [instruction] | Create a linked list with the following elements: 5, 6, 7, 8. [input] |