[output] | def unique_list(list1): unique_list = [] for x in list1: if x not in unique_list: unique_list.append(x) return unique_list # testing list1 = [1,2,2,4,4,4,5] print(unique_list(list1)) # Output: [1, 2, 4, 5] [instruction] | Using the following input and code, edit the code so the output returns a list with only the unique elements from the list. [input] | list1 = [1,2,2,4,4,4,5]
[output] | def is_divisible(x, y): if x % y == 0: print("x is divisible by y") else: print("x is not divisible by y") # testing x = 9 y = 3 print(is_divisible(x ,y)) # Output: x is divisible by y [instruction] | Write code that takes in two numeric variables x and y, and if x is divisible by y, it should print "x is divisible by y"Otherwise it should print "x is not divisible by y". [input] | x = 9, y = 3
[output] | <html> <head> <title>Date and Time</title> </head> <body> <h3 id="date"><script>document.getElementById("date").innerHTML = Date()</script></h3> </body> </html> [instruction] | Create an HTML page that displays the Date and Time in the header. [input] |
[output] | odd = [x for x in numbers if x % 2 != 0] print(odd) # Output: [1, 3, 5, 7, 9] [instruction] | Create a list comprehension that outputs a list of odd numbers from a given list of numbers. [input] | numbers = [1,2,3,4,5,6,7,8,9,10]
[output] | def removeNegative(list1): outputArray = [x for x in list1 if x >= 0] return outputArray # testing list1 = [-1, 1, 2, -2, 3, -3] print(removeNegative(list1)) # Output: [1,2,3] [instruction] | Write a function that creates a new array from a given array of integers, leaving out the negative ones. [input] | list1 = [-1, 1, 2, -2, 3, -3]
[output] | SELECT * FROM Student WHERE grade = 'A'; [instruction] | Code an SQL query to get the records of all students with a grade of ‘A’ in the Student table. [input] | Table Name: Student Columns: id, name, grade
[output] | function fibonacci_array(n) { let sequence = [0, 1]; while (sequence.length <= n) { let lastIndex = sequence.length - 1; sequence.push(sequence[lastIndex] + sequence[lastIndex - 1]); } return sequence; } [instruction] | Write a JavaScript program to create an array of elements, representing the Fibonacci sequence, up to the given number n. [input] |
[output] | Although he was sad. [instruction] | Identify the dependent clause in the given sentence. [input] | Sentence: Although he was sad, he still managed to go to the party.
[output] | JavaScript will automatically create an undeclared variable if it is referenced in the code. The variable is then set to the undefined value. The variable cannot be set or accessed until it has been declared. The variable will also remain in the global scope. [instruction] | How does JavaScript handle undeclared variables? [input] |
[output] | INSERT INTO Students (id, name, grade) VALUES (1, 'John', 'A'), (2, 'Kate', 'B'), (3, 'Steve', 'A'); [instruction] | Code an SQL query to insert new records into the Students table. [input] | Table Name: Students Columns: id, name, grade
[output] | def remove_comments(html_page): comment_start = "<!--" comment_end = "-->" output_page = "" while html_page: comment_start_index = html_page.find(comment_start) if comment_start_index == -1: output_page += html_page break output_page += html_page[:comment_start_index] [instruction] | Remove comments from a given HTML page. [input] |
[output] | i = 1 while i <= 5: print(i) i += 1 [instruction] | Draft a while loop to print the numbers up to and including 5. [input] |
[output] | Gensim summarizer uses text preprocessing, tokenization, and summarization to generate extracted summaries from the given text. It supports manual summarization, latent semantic analysis, Latent Dirichlet Allocation, baseline summarization, and phrases-based summarization. Gensim summarizer provides [instruction] | Summarize the given article using the Gensim summarizer. [input] | [Article about Gensim summarizer](https://gensim.readthedocs.io/en/latest/summarization.html)
[output] | ^([02468]|[13579][0-9]?)$ [instruction] | Formulate a regular expression to identify even numbers up to 100. [input] |
[output] | """ Function which returns factorial of a given number """ def factorial(num): if (num == 0): return 1 else: return num * factorial(num-1) if __name__ == '__main__': print(factorial(5)) [instruction] | Create a function which returns the factorial of a given number. [input] |
[output] | str [instruction] | Find the type of an object for the given object. [input] | Object: "Hello World"
[output] | for [instruction] | Identify the Python statement used for looping. [input] |
[output] | ``` string = "Hello World!" string = string[10:] print(string) ``` [instruction] | Write a code snippet to cut the first 10 characters from a string. [input] | String: "Hello World!"
[output] | list[0] [instruction] | How do you access the first element of the given list? [input] | List = [6, 7, 8]
[output] | """ Validate an email entered by the user """ import re def validate_email(email): regex = '^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$' if(re.search(regex, email)): return True else: return False if __name__ == '__main__': email = input('Enter email address: ') if validate_email(ema [instruction] | Write a code to validate an email entered by the user. [input] |
[output] | [{'country': 'faculty of engineering', 'students': 15000}, {'graduates': 1200}] [instruction] | Parse the data in the given json to a list of key-value dictionaries [input] | {"country": "faculty of engineering", "students": 15000, "graduates": 1200 }
[output] | ^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$ [instruction] | Generate a regex that detects an email [input] |
[output] | print('Name:', d['name']) print('Age:', d['age']) print('Address:', d['address']) [instruction] | Print the contents of the provided dictonary [input] | Dictonary: {'name': 'John', 'age': 23, 'address': '123 Main Street'}
[output] | Minimum: 23 Maximum: 78 [instruction] | Output the smallest and greatest number from the provided list [input] | List: [53, 78, 25, 63, 23, 39]
[output] | print("The name of the person is {name} and his age is {age}".format(name="John Doe", age=23)) [instruction] | Format the following string using the str.format() method. [input] | String: The name of the person is {} and his age is {}
[output] | def check_value(n): if n < 0: raise ValueError("Invalid value") [instruction] | Raise an error with the message "Invalid value" when the following function is called and the value of "n" is below 0. [input] | def check_value(n): # TODO
[output] | The outputs from the logistic regression are [-1, 0.1, 0.6, 1.8]. The labels for these outputs are: -1 = "Negative Class", 0.1 = "Close to Negative Class", 0.6 = "Neutral Class", 1.8 = "Positive Class". [instruction] | Classify and label the outputs from a logistic regression. [input] | [-1, 0.1, 0.6, 1.8]
[output] | def group_list(list): result = {} for element in list: if element in result: result[element] += 1 else: result[element] = 1 return result list = [1, 2, 2, 2, 3, 3, 4, 4, 5] result = group_list(list) print(result) #{1: 1, 2: 3, 3: 2, 4: 2, 5: 1} [instruction] | Write a code to group the elements in a list into a dictionary with the list element as the key and the number of times the element is repeated in the list as the value. [input] | [1, 2, 2, 2, 3, 3, 4, 4, 5]
[output] | SELECT COUNT(DISTINCT column_name) FROM table_name; [instruction] | Generate a query to count the number of unique values in a SQL table. [input] |
[output] | def infix_to_postfix(exp): stack = [] postfix_exp = "" # Convert the expression to a list exp_list = exp.split() for char in exp_list: # If the character is an operand, append it if char in ['A', 'B', 'C']: postfix_exp += char # If the character is an operator, push it [instruction] | Generate a function to convert an infix expression to a postfix expression. [input] | "A + B * C"