[output] | myList = ["one", "two", "three", "four"] newList = [element[0] for element in myList] [instruction] | Convert the following block of code into a more concise version using more appropriate looping mechanisms. [input] | myList = ["one", "two", "three", "four"] newList = [] for element in myList: newList.append(element[0])
[output] | menu = [] menu.extend(table1) menu.extend(table2) [instruction] | Generate a new array by selecting the menu entries associated with each table. [input] | table1 = ["burger", "fries"] table2 = ["pizza", "bbq chicken"]
[output] | for name in names: print(name, len(name)) [instruction] | Write a code snippet that prints out each name and its length. [input] | names = ["John", "Alice", "Paul"]
[output] | multiples_of_3 = [0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30] [instruction] | Generate a list containing all multiples of 3 from 0 to 30. [input] |
[output] | list =[("hello", 1), ("world", 2), ("today", 4), ("is", 3)] sorted_list = sorted(list, key = lambda kv:(kv[0], kv[1])) print(sorted_list) [instruction] | Sort the string list across both key and value. [input] | list =[("hello", 1), ("world", 2), ("today", 4), ("is", 3)]
[output] | import xml.etree.ElementTree as ET tree = ET.parse("doc.xml") root = tree.getroot() [instruction] | Describe a short code fragment that imports xml as an object. [input] |
[output] | mylist = list(range(20)) for i in mylist: print(i) [instruction] | Modify the code to make it compatible with Python 3. [input] | mylist = range(20) for i in mylist: print i
[output] | mylist = [(), (1,), (1, 2), (), (3, 4), (), (5)] filtered_list = list(filter(None, mylist)) print(filtered_list) [instruction] | Remove the empty tuples in the list. [input] | mylist = [(), (1,), (1, 2), (), (3, 4), (), (5)]
[output] | text = "This is an example string" words = text.split() for word in words: if len(word) > 5: print(word) [instruction] | Modify the following code to print all words with more than 5 characters in a given string. [input] | text = "This is an example string"
[output] | def replace_char(text): if len(text) > 5: return text.replace('e','E') else: return text [instruction] | Write a python program to replace the character ‘e' with the character ‘E' for strings of length more than 5 [input] | text = "Hello world!"
[output] | def split_list(data, n): output = [data[i:i+n] for i in range(0, len(data), n)] return output [instruction] | Write a Python function to split a list of items into groups of n. [input] | list = ["red", "green", "orange", "blue", "pink", "purple"]
[output] | def contains_item(data, item): return item in data [instruction] | Write a Python program to check if a list contains a specific item. [input] | data = [3, 4, 5, 6, 7]
[output] | def most_freq_char(s): freq_dict = {} for char in s: if char in freq_dict: freq_dict[char] += 1 else: freq_dict[char] = 1 max_freq = 0 max_char = "" for key in freq_dict: if max_freq < freq_dict[key]: max_freq = freq_dict[key] max_char = key return s.index(max_char) [instruction] | Given a string s, create a function to find the character that appears the most and return its index. [input] | s = "Big Data"
[output] | from bs4 import BeautifulSoup html_doc = """ <html><head><title>Page Title</title></head> <body> <h1>Header Text</h1> <p>Paragraph 1</p> <p>Paragraph 2</p> </body> </html> """ soup = BeautifulSoup(html_doc, 'html.parser') text_content = soup.find_all(text=True) for content in text_content: pr [instruction] | Parse a HTML page and find all text content within the page. [input] |
[output] | SELECT * FROM employees ORDER BY salary DESC limit 5; [instruction] | Create a SQL query to return top five rows from a table named 'employees'. [input] |
[output] | def sort_strings(lst): return sorted(lst, key=str.lower) [instruction] | Given a list of strings, write a function to sort them alphabetically. [input] | ["orange", "apple", "banana"]
[output] | import hashlib def generate_token(algorithm, size, encoding): token = hashlib.sha256(os.urandom(size//2)).hexdigest()[:size] return token [instruction] | Generate a token based on the given parameters. [input] | Parameters: Algorithm (SHA-256), Size (32 characters), Encode (Hexadecimal)
[output] | list_1[0] = 3 list_1[1] = 6 list_1[2] = 9 list_1[3] = 12 [instruction] | Assign the values of list_2 to the same positions of list_1. [input] | list_1 = [1, 2, 5, 8] list_2 = [3, 6, 9, 12]
[output] | This code creates a div element which contains an h3 for a title, a p for a paragraph, and a button element. It will be rendered as a box with the title at the top, followed by the paragraph and button below it. [instruction] | Analyze the given HTML code. [input] | <div> <h3>Title</h3> <p>paragraph</p> <button>Button</button> </div>
[output] | A function call statement in JavaScript looks like: functionName(parameter1, parameter2, ...); [instruction] | What does a function call statement look like in JavaScript? [input] |
[output] | The else statement in an if-else statement is used to execute a block of code when the expression in the if statement returns false. It provides an alternate option if the condition in the if statement is not satisfied. The else statement can be followed by an additional if-else statement in order t [instruction] | Describe the purpose of the else statement in an if-else statement. [input] |
[output] | #include <iostream> int main() { int a = 2; int b = 3; int sum = a + b; std::cout << sum << std::endl; return 0; } [instruction] | Create a C++ program to sum two integers and output the value. [input] | 2 3
[output] | let num1 = 6 let num2 = 10 let num3 = 2 let max = Swift.max(num1, num2, num3) print(max) [instruction] | Create a Swift program that takes three numbers and outputs the maximum between them. [input] | 6 10 2
[output] | for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { Console.WriteLine("{0} * {1} = {2}", i, j, (i * j)); } Console.WriteLine(); } [instruction] | Generate a C# program to print out the results of a multiplication table from 1 to 10. [input] |
[output] | #include <stdio.h> #include <math.h> int main() { int binary=10101; int decimal=0, i=0, rem; while (binary!=0) { rem=binary%10; decimal=decimal+rem*pow(2,i); binary=binary/10; ++i; } printf("The hexadecimal equivalent is : %x", decimal); r [instruction] | Convert a given number from binary to hexadecimal using C programming language. [input] | 10101
[output] | SELECT email FROM users WHERE email LIKE '%@%.%'; [instruction] | In SQL, write an expression to output all valid email addresses from a table of users. [input] |
[output] | let a = 12; let b = 8; [instruction] | Change the given program code to swap the values of two variables 'a' and 'b'. [input] | let a = 8; let b = 12;
[output] | 11 13 15 17 19 [instruction] | Write the output for the following Java program. [input] | public class OddNumber { public static void main(String[] args) { for(int i=10; i<20; i++) { if(i % 2 == 1) { System.out.println(i); } } } }
[output] | { "name1": "value1", "name2": "value2" } [instruction] | Convert the given hashmap ['name1': 'value1', 'name2': 'value2' ] to JSON. [input] |
[output] | An exception is handled in a C# program by using the try/catch statement. The statement provides a way to handle any potential errors that may occur while executing the program. It allows you to define a section of code that can execute even if an exception or error is encountered. [instruction] | How is an exception handled in a C# program? [input] |