[output] | import json data = [ { "id": "12345", "model": "Honda", "year": 2021 } ] data[0]["color"] = "red" json_object = json.dumps(data, indent = 4) print(json_object) Output: [ { "id": "12345", "model": "Honda", "year": 2021, "color": [instruction] | Create a Python script to add a new field of “car color” to the given JSON object. [input] | { "id": "12345", "model": "Honda", "year": 2021 }
[output] | cars = ["Tesla Model 3", "Tesla Model X", "Toyota Corolla", "Kia Soul EV", "Ford Fusion"] for car in cars: if "EV" in car: print(car) Output: Tesla Model X Kia Soul EV [instruction] | Go through the following list of car models, and print out only the names of all-electric vehicles. [input] | Tesla Model 3 Tesla Model X Toyota Corolla Kia Soul EV Ford Fusion
[output] | import xmltodict import json json_object = { "username": "John123", "age": 23, "country": "USA" } xml_message = xmltodict.unparse(json.loads(json.dumps(json_object)), pretty=True) print(xml_message) Output: <root> <username>John123</username> <age>23</age> <country>USA</country> </root [instruction] | Create a Python script to convert the given JSON object into an XML document. [input] | { "username": "John123", "age": 23, "country": "USA" }
[output] | function getValues(objList, key) { let results = []; objList.forEach(function(obj) { if (obj.hasOwnProperty(key)) { results.push(obj[key]); } }); return results; } let ages = getValues(objList, 'age'); console.log(ages); Output: [25, 28, 31] [instruction] | Given the following list of JavaScript objects and a particular key, write a function to return an array of the values corresponding to that key. [input] | [ { "name": "John", "age": 25 }, { "name": "Jane", "age": 28 }, { "name": "Dave", "age": 31 } ], key = 'age'
[output] | my_list = [2, 4, 10, 20] def average(nums): return sum(nums) / len(nums) print(average(my_list)) Output: 8.0 [instruction] | Create a Python program to find the average of the given numbers in the list [input] |
[output] | This code snippet is a function declaration named sayHello() which takes one argument, 'name'. It prints a string containing the word "Hello" and the value of the 'name' argument to the console. It is a common way to communicate with the user through console messages. [instruction] | Explain this JavaScript code snippet. [input] | function sayHello(name) { console.log('Hello ' + name); }
[output] | The object literal notation is a way to create an object in JavaScript by wrapping the set of comma-separated key: value pairs in curly braces. For example, to create an object containing two properties, you can write: var obj = { name: 'John', age: 22 }; [instruction] | How do we create an object in JavaScript using the object literal notation? [input] |
[output] | public class Calculator { // Function to add two numbers public int add(int num1, int num2) { return num1 + num2; } // Function to subtract two numbers public int subtract(int num1, int num2) { return num1 - num2; } // Function to multiply [instruction] | Create a program in Java to create a simple calculator that has the ability to add, subtract, multiply, and divide numbers. [input] |
[output] | Data can be stored persistently on the user's machine with various web storage APIs such as localStorage and sessionStorage. LocalStorage enables an application to store data on the user's computer with no expiration date, while sessionStorage stores information that can only be accessed while the a [instruction] | How can we store data persistently on the user's machine? [input] |
[output] | SELECT customer.* FROM customer JOIN review ON review.customer_id = customer.id WHERE customer.state = 'California' GROUP BY review.customer_id HAVING COUNT(review.customer_id) > 5; [instruction] | Construct a SQL query to find all the customers who live in California and have more than 5 reviews. [input] |
[output] | func swap(a: inout Int, b: inout Int) { let temp = a a = b b = temp } [instruction] | Implement a function in Swift to swap two integer variables. [input] | Two integers a and b.
[output] | document.getElementById('submitButton').addEventListener('click', function() { // code to run when button is clicked }); [instruction] | Write a JavaScript code snippet to add an event listener to a button with the ID 'submitButton'. [input] |
[output] | The most common way to iterate through an object in JavaScript is to use a for-in loop. It will loop through the object's properties and execute the code within the loop for each property. For example: let obj = { a: 1, b: 2, c: 3 }; for (let property in obj) { console.log(property + ':' obj[ [instruction] | Show a way to iterate through an object in JavaScript. [input] |
[output] | Proxy objects in JavaScript enable developers to intercept and customize operations performed on objects. It acts as a bridge between the concept of direct object property access and the actual implementation behind the scenes. The proxy wraps the incoming object and observes all operations performe [instruction] | Explain how proxy objects work in JavaScript. [input] |
[output] | Memory leaks in Java can be prevented by following certain coding practices. Firstly, it is important to ensure proper object references are maintained, so that objects are not unintentionally retained in memory for long periods of time. Secondly, it is important to be mindful of resource usage, suc [instruction] | How can we prevent memory leaks in Java? [input] |
[output] | SELECT firstname, lastname FROM customers WHERE orderid = 30; [instruction] | Create an SQL query to select the "firstname" and "lastname" of the customers with an orderid of 30. [input] |
[output] | <?php function callback($fruitname, $price) { echo $fruitname.' costs '.$price.' dollars'; } ?> [instruction] | Create a PHP callback given the following parameters "fruitname" and "price". [input] |
[output] | echo "five"; [instruction] | Edit the following code snippet to output "five" instead of "four". [input] | echo "four";
[output] | <!DOCTYPE html> <html> <head> <title>My Website</title> </head> <body> <h1>Welcome to My Website</h1> <p>This is the homepage of My Website.</p> <button type="button">Click Here</button> </body> </html> [instruction] | Create an HTML page with a heading, aparagraph and a button that says "Click Here". [input] |
[output] | function combine(arr1, arr2) { const combinedArr = []; for(let i=0; i<arr1.length; i++) { combinedArr.push(arr1[i], arr2[i]); } return combinedArr; } [instruction] | Write a JavaScript function that takes in two arrays of equal length, and returns a third array with elements from both arrays. [input] | [1, 2, 3], [10, 20, 30]
[output] | .important { color: red; } [instruction] | Write a CSS style to change the text color to red for all elements with the class "important". [input] |
[output] | class Rectangle: def __init__(self, length, width): self.length = length self.width = width [instruction] | Create a basic python object that stores the length and width of an rectangle. [input] |
[output] | public void EditList(List<string> list, string oldVal, string newVal) { for(int i = 0; i < list.Count; i++ ) { if (list[i] == oldVal){ list[i] = newVal; } } } [instruction] | Create a C# function to edit the contents of a list. [input] |
[output] | <form action="" method="post"> <label>Username:</label> <input type="text" name="username"> <label>Password:</label> <input type="password" name="password"> <label>Confirm Password:</label> <input type="password" name="confirm_password"> <input type="submit" value="Submit"> </form> [instruction] | Generate an HTML form with three fields "username", "password" and "confirm password". [input] |
[output] | def combine_strings(str1, str2) str1 + " " + str2 end [instruction] | Write a function in Ruby that takes in two strings and returns a new string that contains both strings with a space in between them. [input] |
[output] | if (x > 10) { // Do something... } [instruction] | You need to add an if statement to this existing code. The if statement should check if the given number stored in the variable x is larger than 10. [input] | int x = 5;
[output] | let x = 0; let y = 1; for (let i = 0; i < 10; i++) { let z = x + y; console.log(z); x = y; y = z; } [instruction] | Write a JavaScript program that will console log the first 10 numbers of the Fibonacci sequence. [input] |
[output] | let x = 0; let y = 1; for (let i = 0; i < 5; i++) { let z = x + y; console.log(z); x = y; y = z; } [instruction] | Create a for loop that prints the first five numbers of the Fibonacci sequence. [input] |
[output] | myDictionary = { 'apple': 'fruit', 'celery': 'vegetable', 'sun': 'star', 'earth': 'planet', 'light': 'energy' } [instruction] | You need to create a dictionary that contains five elements with their associated values. [input] |
[output] | SELECT * FROM users WHERE name = "John"; [instruction] | You need to generate an SQL query that will return records from a table called "users" where the name matches the given parameter. [input] | John