text
stringlengths
141
2.89k
⌀
instruction
stringlengths
19
1.5k
⌀
input
stringlengths
0
800
⌀
output
stringlengths
1
2.5k
⌀
null
Insert a line of code to change the value of the string "text" to "Hello World".
String text = "";
String text = ""; text = "Hello World";
null
Use JavaScript to filter an array of numbers such that only even numbers are returned.
[1, 4, 6, 7, 8, 3, 10]
const arr = [1, 4, 6, 7, 8, 3, 10]; const evenArr = arr.filter(num => num % 2 == 0); console.log(evenArr); // Output: [4, 6, 8, 10]
null
Implement a function to find the longest common subsequence between two strings in Python.
str1 = "abcdabcd", str2 = "bcdee"
def lcs(str1, str2): n = len(str1) m = len(str2) # Create a matrix to store # results of subproblems LCSuff = [[0 for k in range(m+1)] for l in range(n+1)] # Fill the LCSuff matrix in # bottom up manner for i in range(n+1): for j in range(m+1): if (i ==...
null
Write a code in Python to sort a list of integers with the following conditions: - Numbers greater than zero should be sorted in ascending order. - Numbers equal to zero should remain unchanged. - Numbers less than zero should be sorted in descending order.
[-2, 7, 0, 8, -3]
def sort_list(numbers): result = [] positive_numbers = [] negative_numbers = [] #separate negative and positive numbers for i in numbers: if i > 0: positive_numbers.append(i) elif i < 0: negative_numbers.append(i) else: result.append(i) #sort the positive numbers positi...
null
Write a SQL query to filter out records that contains an empty string.
Table 1: Name | Job | City -----|-----|------- John | Programmer | Jane | Office Assistant | San Francisco Bob | Designer |
SELECT * FROM Table_1 WHERE Job != '' AND City != '';
null
Convert the given input string to lower case keeping all other characters same.
FEDCbA
fedcba
null
Find the largest and smallest number in a given list.
[5, 10, 20, 7, -8, 15]
import math my_list = [5, 10, 20, 7, -8, 15] largest = max(my_list) smallest = min(my_list) print("Largest element is:", largest) print("Smallest element is:", smallest)
null
Write a Python function to convert a given floating point number to binary.
19.66
def decimal_to_binary(f_num): b_str = "" int_num = int(f_num) f_num = f_num - int_num while int_num > 0: b_str = str(int_num % 2) + b_str int_num //= 2 b_str = "1." + b_str while f_num > 0: f_num *= 2 int_num = int(f_num) if int_num == 1: b_str += "1" else: b_str += "...
null
Convert a list of strings to a list of integers.
list_of_strings = ["1", "2", "3"]
list_of_ints = [1, 2, 3]
null
Design an API in Python that stores a list of books in a database. The API should be capable of retrieving the list, inserting a new book, deleting a book, and updating a book's data.
Not applicable
import sqlite3 class LibraryAPI: def __init__(self): self.db_conn = sqlite3.connect('library.db') self.db_cursor = self.db_conn.cursor() def get_books(self): book_list = [] self.db_cursor.execute('SELECT * FROM books') books = self.db_cursor.fetchall() for book in books: book_dict = {} book_dic...
null
Write a function to generate a set of random numbers in Python.
import random def generate_randoms(n): # generate a set of n random numbers rands = [] for _ in range(n): rands.append(random.randint(1,100)) return rands generate_randoms(10)
null
Write the output for the following Java program.
public class OddNumber { public static void main(String[] args) { for(int i=10; i<20; i++) { if(i % 2 == 1) { System.out.println(i); } } } }
11 13 15 17 19
null
Create a SQL query to update the 'name' on table 'employees' with the value 'User 1' where the id is 1.
UPDATE employees SET name = 'User 1' WHERE id = 1;
null
Write a Python script to perform linear regression on a given dataset.
[[5, 6], [3, 4], [7, 9], [4, 5]]
import numpy as np from sklearn.linear_model import LinearRegression x = np.array([[5, 6], [3, 4], [7, 9], [4, 5]]) y = np.array([7, 5, 11, 7]) model = LinearRegression().fit(x, y) print(model.coef_) print(model.intercept_)
null
Generate code using Python to find the largest and smallest number in a given list.
[2, 3, 5, 8, 1, 9, 4]
def min_max(array): min_val = array[0] max_val = array[0] for element in array: if(element > max_val): max_val = element if(element < min_val): min_val = element return (min_val, max_val)
null
Normalize a given vector.
vector = [2, 5, 6]
# Calculate sum of vector elements vector_sum = 0 for x in vector: vector_sum += x # Normalize vector normalized_vector = [x/vector_sum for x in vector] # Print the normalized vector print(normalized_vector)
[HI Wikipedia] तुएनसांग तुएनसांग (Tuensang) भारत के नागालैण्ड राज्य के तुएनसांग ज़िले में स्थित एक नगर है। यह ज़िले का मुख्यालय भी है। विवरण यह पूर्व में स्थित बर्मा देश से कुछ ही दूरी पर है। नागालैण्ड का सबसे ऊँचा पहाड़, सारामाती पर्वत, तुएनसांग के काफ़ी पास है और भारत-बर्मा सीमा पर स्थित है। ट्वेनसांग शहर की स्थापना...
null
null
null
null
Create a HTML page containing an input field, a submit button and a table for displaying the results.
<html> <head> <title>A Sample HTML Page</title> </head> <body> <form> <input type="text" id="input-field" /> <input type="submit" value="Submit" /> </form> <table> <tr> <th>Results</th> </tr> <tbody id="results-table"> </tbody> </table> </body> </html>
null
Write an SQL query that returns the sum of inventories in the Inventory table.
SELECT SUM(Amount) FROM Inventory;
null
Write a Python program to generate the first n Fibonacci numbers.
def generate_fibonacci_numbers(n): if n==1: return [0] elif n==2: return [0,1] else: fib_list = [0,1] for i in range(2,n): fib_list.append(fib_list[i-1]+fib_list[i-2]) return fib_list
null
Create a Python program to parse a HTML page and extract all the hyperlinks from it.
let html = `<html> <body> <a href="http://www.example.com">Link 1</a> <a href="http://www.example.org">Link 2</a> <a href="http://www.example.net">Link 3</a> </body> </html>`
from html.parser import HTMLParser class LinkParser(HTMLParser): def handle_starttag(self, tag, attrs): if tag == 'a': for (attrs,value) in attrs: if attrs=='href': print(value) parser = LinkParser() parser.feed(html)
null
Implement a function in Python that takes a 2-dimensional list of integers and returns a list with the same shape, containing the sums of previous elements from left to right.
[[1, 2, 1], [2, 3, 4], [1, 4, 6]]
def accumulator_add(matrix): output_matrix = [] #iterates over all sublists for row in matrix: #creates a new sublist to store the sums output_sublist = [] sum = 0 #iterates over all elements in the sublist for sublist_element in rows: #adds the element to the tota...
null
Create a Python program that returns the index of an integer in a sorted array.
Given a sorted array arr[] = {1, 2, 3, 5, 6, 8, 9}, and an integer x = 8
def binarySearch(arr, x): l = 0 r = len(arr)-1 while l <= r: mid = l + (r - l)//2 if arr[mid] == x: return mid elif arr[mid] < x: l = mid + 1 else: r = mid - 1 return -1
null
Edit the given HTML code so that the paragraphs are numbered.
<p>These are some sample paragraphs.</p> <p>This is another one.</p>
<ol> <li><p>These are some sample paragraphs.</p></li> <li><p>This is another one.</p></li> </ol>
null
Optimize the following Python code to sort a set of numbers (set = [2, 6, 3, 8, 4]) in O(n) time complexity.
unsorted_list = [2, 6, 3, 8, 4]
def sort_list(unsorted_list): sorted_list = [] while unsorted_list: min_elem = min(unsorted_list) unsorted_list.remove(min_elem) sorted_list.append(min_elem) return sorted_list
[HI Wikipedia] ज़ूग कैन्टन ज़ूग कैन्टन (जर्मन व अंग्रेज़ी: Zug), जिसे कभी-कभी त्ज़ूग कैन्टन भी उच्चारित किया जाता है, स्विट्ज़रलैंड के मध्य भाग में स्थित एक कैन्टन (प्रान्त से मिलता-जुलता प्रशासनिक विभाग) है। यह कैन्टन सन् १३५२ में स्विस परिसंघ का हिस्सा बना था। केवल २३९ वर्ग किमी का यह कैन्टन ज़िलों में विभाजित नहीं ...
null
null
null
null
Create a JavaScript class to represent a rectangle with properties for width and height.
class Rectangle { constructor(width,height) { this.width = width; this.height = height; } }
null
Find the first unique number in the list.
[1,2,3,4,5,5,4,3,2,1,6]
6
null
Write a Python program to extract all words from a sentence and print them.
The quick brown fox
sentence = "The quick brown fox" words = sentence.split(" ") for word in words: print(word) # Output # The # quick # brown # fox
null
Create a jQuery function that animates an element's background color from red to green over 3 seconds.
$("#element").animate({ backgroundColor: "green" }, { duration: 3000, easing: "linear" });
null
Implement a Python code that takes a string and reverses the characters in place.
string = "This is easy"
def reverse_in_place(string): return string[::-1]
null
This code sends data to a USB device and waits for a reply, then displays it. To use it, run the script with the device and data to send as arguments. The device argument should be in the form of either "/dev/ttyUSB0" or "COM1". The data can be in the form of either "0xhexcodes" or "string". If the first data argument ...
#!/usr/bin/env python # Copyright 2012-2013 Xiangfu # Copyright 2012-2013 Andrew Smith # Copyright 2013 Luke Dashjr # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 3 of the Lice...
null
Write a loop that prints the numbers from 0 to 9 on the console.
for (let i = 0; i < 10; i++) { console.log(i); }
null
Create a class in Python to represent a bank account and add methods to display, withdraw, deposit and transfer money.
The bank account has the following details: - Customer Name: John Doe - Account Number: 12345 - Balance: $1000
class BankAccount: def __init__(self, customer_name, account_number, balance): self.customer_name = customer_name self.account_number = account_number self.balance = balance def display_balance(self): print('Your balance is', self.balance) def withdraw_amount(self, amount): self.balance -= amount print('You withdrew', ...
null
Write a Python script to validate the following input
Validate a Date type field with the following format: YYYY/MM/DD
# Import the required datetime module import datetime def validate_date(date): # Check if the date matches with the given format try: datetime.datetime.strptime(date, '%Y/%m/%d') return True except ValueError: return False
null
Using the code snippet given below, add a unique class called btn which will remove the default styles from the submit button.
<form action="/contact.php"> <input type="text" name="name"> <input type="email" name="email"> <input type="submit" value="Submit"> </form>
<form action="/contact.php"> <input type="text" name="name"> <input type="email" name="email"> <input type="submit" value="Submit" class="btn"> </form>
[DE Wikipedia] Liste der Kulturgüter im Bezirk Aigle Die Liste der Kulturgüter im Bezirk Aigle enthält alle Objekte in den Gemeinden des Bezirks Aigle im Kanton Waadt, die gemäss der Haager Konvention zum Schutz von Kulturgut bei bewaffneten Konflikten, dem Bundesgesetz vom 20. Juni 2014 über den Schutz der Kulturgüte...
null
null
null
null
Create a program in Python to print out the elements in a list in reverse order.
List = ["A", "B", "C", "D"]
list = ["A", "B", "C", "D"] for i in range(len(list)-1, -1, -1): print(list[i])
null
Can you generate a Python loop to print out each item in a given list?
myList = ["item1", "item2", "item3"] for item in myList: print(item)
null
Create a program that assigns an ID to each element of an array.
arr = ["Car", "Bike", "Bus"]
# Create program that assigns an ID to each element of an array arr = ["Car", "Bike", "Bus"] # Initialize a counter counter = 0 # Loop over each element of the array for element in arr: # Assign an ID to the element (in this case, the counter value) element_id = counter # Print the assigned ID print(f"Element {element}...
[DE Wikipedia] Karl-Heinz Warnholz Karl-Heinz Warnholz (* 24. April 1944 in Geesthacht) ist ein Hamburger Politiker der CDU. Leben und Politik Karl-Heinz Warnholz ist gelernter Bautechniker und trat 1964 in die Bundeswehr als Berufssoldat ein. 1994 beendete er seine Arbeit dort und begann im selben Jahr mit der Geschä...
null
null
null
null
Construct a program in Python that computes the sum of 3rd and 7th elements of a list.
list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
def sum_elements(list): Sum = list[2] + list[6] return Sum print(sum_elements(list))
[EN Wikipedia] Hamamelistes Hamamelistes is a genus of true bugs belonging to the family Aphididae. The species of this genus are found in Europe and Northern America. Species: Hamamelistes betulinus (de Horváth, 1896) Hamamelistes cristafoliae (Monzen, 1954) Hamamelistes spinosus (Shimer, 1867) — Spiny Witch-Hazel Ga...
null
null
null
null
Optimize the performance of a given Python script.
import time def optimize_performance(function): start_time = time.time() function end_time = time.time() execution_time = end_time - start_time print("Function took", execution_time, "seconds to execute.") # perform optimizations optimized_function = function start_time = time.time() ...
[HI Wikipedia] भारतीय दर्शन में परमाणु भारतीय दर्शन में परमाणु का उल्लेख पाश्चात्य विज्ञान से कई सदी पहले ही हो गया था। परमाणु और अणु, कई मतों के अनुसार एक ही तत्व से दो नाम हैं। भिन्न भिन्न दर्शन के अनुसार परमाणुओं का अपने तरीके से वर्णन किया गया हैं। परंतु इसका सारांश यह ही निकलता हैं कि परमाणु पदार्थ का सबसे सूक्ष्...
null
null
null
null
Using C++, write a program to sort an array of strings alphabetically.
["Hello", "World", "This", "Is", "A", "Test"]
#include<iostream> #include<algorithm> using namespace std; int main() { string arr[] = { "Hello", "World", "This", "Is", "A", "Test" }; int n = sizeof(arr) / sizeof(arr[0]); sort(arr, arr + n); for (int i = 0; i < n; i++) cout << arr[i] << " "; return 0; }
null
Create an algorithm to detect if a string is a palindrome or not.
def isPalindrome(s): reversedString = s[::-1] if (s == reversedString): return True return False
null
Take in an array of integers and return the sum of all odd numbers.
[1,2,3,4,5]
9
null
List the layers of an artificial neural network.
The layers of an artificial neural network typically include an input layer, one or more hidden layers and an output layer. In addition, some ANNs also include a convolutional layer and/or a pooling layer.
null
Write a Python function to check if a given string is an anagram of another or not.
word1 = "cat" word2 = "tac"
def is_anagram(word1, word2): return sorted(word1) == sorted(word2)
null
Create a Python class that defines a circle with a radius.
class Circle: def __init__(self, radius): self.radius = radius def get_area(self): return 3.14 * (self.radius ** 2) def get_circumference(self): return 2 * 3.14 * self.radius
null
Print only the odd numbers from the given list.
list_items = [2, 3, 4, 5, 6, 7, 8]
""" Print only the odd numbers from the given list """ list_items = [2, 3, 4, 5, 6, 7, 8] for item in list_items: if item % 2 != 0: print(item)
null
Create a function that takes in an integer "n" and prints all perfect numbers between 0 to n.
n = 20
def perfect_numbers(n): perfect_numbers = [] for number in range(1, n+1): sum_divisors = 0 for divisor in range(1, number): if number % divisor == 0: sum_divisors += divisor if sum_divisors == number: perfect_numbers.append(number) return perfect_numbers print(perfect_numbers(n))
null
Write a code to count the occurrences of a particular element in a given list.
list1 = [1, 2, 3, 3, 3, 4, 5] element = 3
def count_occurrences(list1, element): count = 0 for elem in list1: if elem == element: count += 1 return count if __name__ == "__main__": print("Number of occurrences of", element, "in the list:", count_occurrences(list1, element))
null
Write a nod.js code to return the current system time.
let currentTime = new Date().toLocaleTimeString(); console.log(currentTime);
null
What is a function pointer?
A function pointer is a variable that holds the address of a function. It can be used to invoke a specific function based on the address stored in the pointer. It is commonly used in C and C++.
null
Given a class definition, write a method to count the number of objects created in the class.
class Student: def __init__(self, name, age): self.name = name self.age = age
class Student: _count = 0 def __init__(self, name, age): self._count += 1 self.name = name self.age = age @classmethod def get_count(cls): return cls._count
null
Write a Python program to search for a specific word in a given string and return the number of times the string appears.
String: "Hello, world! This is a sample message." Word: "hello"
string = "Hello, world! This is a sample message." word = "hello" count = string.lower().split().count(word.lower()) print(f"The word {word} appears {count} times in the given string.")
null
Explain the importance and use of an algorithm in computing.
An algorithm is a step-by-step process that a computer can use to solve a problem or achieve a goal. Algorithms are essential to computing systems, as they provide methods for inputting, storing, interpreting, manipulating, and outputting data. Algorithms can process data with speed, accuracy, and reliability, and can ...
[HI Wikipedia] सनातन धर्म सनातन धर्म हिंदू धर्म का एक संप्रदाय है जिसका उपयोग आम हिंदू धर्म के साथ-साथ संस्कृत और अन्य भारतीय भाषाओं में भी किया जाता है। सनातन धर्म को हिंदू धर्म का एक संप्रदाय माना जाए या नहीं, इस पर दुनिया भर के हिंदुओं में मतभेद है, क्योंकि सनातन धर्म ऐतिहासिक वैदिक धर्म पर आधारित है, या हिंदू धर्म...
null
null
null
null
Create a Python program to remove the characters from specific index within a string.
mystring = "Hello, World!" index = 5
mystring = "Hello, World!" index = 5 result = mystring[:index] + mystring[index+1:] print("Result after removing characters from index {}: {}".format(index, result))
[EN Wikipedia] Laura Emma Marshall Jamieson Laura Emma Marshall Jamieson (December 29, 1882 – June 30, 1964) was an educator and political figure in British Columbia. She represented Vancouver Centre in the Legislative Assembly of British Columbia from 1939 to 1945 and from 1952 to 1953 as a Co-operative Commonwealth ...
null
null
null
null
Create a Python function that takes in two parameters (n,k) and returns the value of n^k.
def power(n,k): result = 1 for i in range(0,k): result *= n return result
null
Use Java to send an HTTP request to an API endpoint with a login form.
import java.net.*; import java.io.*; public class HttpClient { public static void main(String[] args) { try { URL url = new URL("http://example.com/api/login"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); // Request headers con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "appl...
null
Write a code snippet that prints the current date and time in the format YYYY-MM-DD HH:MM:SS.
import datetime # Get the current datetime now = datetime.datetime.now() # Prints the current datetime in YYYY-MM-DD HH:MM:SS format print(now.strftime("%Y-%m-%d %H:%M:%S"))
null
Predict the output of the following Python program.
my_list = [1,2,3,4,5] x = 0 for i in my_list: x += i print(x)
15
null
Using CSS, create a simple page layout with two columns of equal width.
width: 600px
<style> #container { width: 600px; } #container div { float: left; width: 50%; } </style> <div id="container"> <div>Content for the first column</div> <div>Content for the second column</div> </div>
null
Rewrite the following Python class as an JavaScript class with equivalent functions: class Person: def __init__(self, name): self.name = name def greet(self): print(f"Hello, my name is {self.name}")
Not applicable
class Person { constructor(name) { this.name = name; } greet() { console.log(`Hello, my name is ${this.name}`); } }
null
Write a regular expression to match the email address "test@example.com".
^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$
null
Write a Python program to clean a given text from unwanted words and punctuations.
A raw string
import string def clean_text(text): # remove punctuation translator = str.maketrans('', '', string.punctuation) text = text.translate(translator) # remove unwanted words unwanted_words = {'the', 'and', 'a'} words = text.split(' ') words = [word for word in words if word not in unwanted_words] return ' '.j...
[HI Wikipedia] पर्दा प्रथा पर्दा एक इस्लामी शब्द है जो अरबी भाषा में फारसी भाषा से आया। इसका अर्थ होता है "ढकना" या "अलग करना"। पर्दा प्रथा का एक पहलू है बुर्क़ा का चलन। बुर्का एक तरह का घूँघट है जो मुस्लिम समुदाय की महिलाएँ और लड़कियाँ कुछ खास जगहों पर खुद को पुरुषों की निगाह से अलग/दूर रखने के लिये इस्तेमाल करती हैं...
null
null
null
[HI Wikipedia] अटल बिहारी वाजपेयी हिन्दी विश्वविद्यालय अटल बि‍हारी वाजपेयी हि‍न्‍दी वि‍श्‍ववि‍द्यालय भोपाल में स्थित एक विश्वविद्यालय है। 6 जून 2013 में भारत के तत्कालीन राष्ट्रपति श्री प्रणव मुखर्जी ने इसकी की आधारशि‍ला रखी। यह विश्वविद्यालय तकनीकी, चिकित्सा, कला और वाणिज्य से जुड़े विषयों की शिक्षा प्रदान करेगा। मध्...
null
null
null
[CS Wikipedia] Fakulta informačních technologií ČVUT Fakulta informačních technologií ČVUT v Praze (FIT ČVUT) byla založena 1. července 2009 jako osmá fakulta ČVUT. Jejím prvním děkanem se stal Pavel Tvrdík, který byl děkanem zvolen znovu i v roce 2013. Pro období 2017–2021 byl v červnu 2017 novým děkanem zvolen Marce...
null
null
null
null
Generate a program in Python to extract all numbers from a given string
string = "The 3 monkeys had 2 apples"
import re def extract_numbers(string): numbers = re.findall('\d+', string) return numbers string = "The 3 monkeys had 2 apples" print(extract_numbers(string))
null
Perform sentiment analysis on the given text using NLTK library in Python.
The food here is amazing.
from nltk.sentiment.vader import SentimentIntensityAnalyzer sentences = ["The food here is amazing!"] sid = SentimentIntensityAnalyzer() for sentence in sentences: ss = sid.polarity_scores(sentence) print("for sentence: {}, sentiment analysis: {}".format(sentence, ss)) # Output # for sentence: The food here is amazing!...
null
Implement a Python function to check if an integer is even or odd.
def is_even(num): return num % 2 == 0
null
Using the input, classify whether the number is even or odd.
num = 5
if num % 2 == 0 puts "The number is even" else puts "The number is odd" end
[HI Wikipedia] ज़ैन-उल-अबिदीन सुल्तान ग़ियास​-उद​-दीन ज़ैन​-उल-अबिदीन (Zain-ul-Abidin, ) मध्यकालीन कश्मीर में १४२३-१४७४ काल में राज करने वाले एक सुल्तान थे जिनका राज्य आधुनिक भारत के जम्मू व कश्मीर राज्य पर विस्तृत था। वे मध्यकालीन कश्मीर के सबसे महान शासकों में से एक गिने जाते हैं जिन्होनें सर्वधार्मिक उदारता और प्रश...
null
null
null
null
Write a Python script to check for syntactic correctness of an algorithm.
Algorithm = "1. Read input 2. Initialize variables 3. Process input 4. Output result"
def is_algorithm_syntactically_correct(algorithm): algorithm = algorithm.replace('\n', ' ').replace('\t ', ' ').lower() required_words = ['read', 'input', 'initialize', 'variables', 'process', 'output', 'result'] for word in required_words: if word not in algorithm: return False return True
[HI Wikipedia] घर्षणमारक धातु एवं मिश्रातु घर्षणमारक धातु एवं मिश्रातु (Antifriction metals and alloys) वे धातुएँ तथा मिश्रातु है जो परस्पर घिसकर चलने वाले दो मशीन-पुर्जों के बीच घर्षण गुणांक को कम करने में सहायक होती हैं तथा घर्षण के कारण स्वयं भी कम घिसती हैं। परिचय घूमनेवालों चक्कों अथवा पहियों के अबाध गति से चलते ...
null
null
null
null
Edit a given Python program to add error handling to it.
def read_csv(filename): with open(filename, 'r') as f: data = f.readlines() return data
def read_csv(filename): try: with open(filename, 'r') as f: data = f.readlines() return data except FileNotFoundError: print("File not found. Please provide a valid filename")
[HI Wikipedia] अरुणाचल प्रदेश अरुणाचल प्रदेश भारत का एक उत्तर-पूर्वी राज्य है। अरुणाचल का अर्थ "उगते सूर्य का पर्वत" है (अरूण + अचल ; 'अचल' का अर्थ 'न चलने वाला' = पर्वत होता है।)। प्रदेश की सीमाएँ दक्षिण में असम दक्षिणपूर्व में नागालैंड पूर्व में बर्मा/म्यांमार पश्चिम में भूटान और उत्तर में तिब्बत से मिलती हैं। ईटानग...
null
null
null
null
Explain what is hyperparameter tuning and provide a basic example.
Hyperparameter tuning is the process of selecting the optimal hyperparameters of a machine learning algorithm. Hyperparameters are static values that define the behaviors and characteristics of the algorithm, such as learning rate, activation functions and regularization terms. An example of hyperparameter tuning is se...
null
Write a function to calculate median of array elements
def get_median(arr): sorted_arr = sorted(arr) length = len(sorted_arr) if length % 2 == 0: median1 = sorted_arr[int(length/2) - 1] median2 = sorted_arr[int(length/2)] median = (median1 + median2) / 2 else: median = sorted_arr[int((length-1)/2)] return median
[EN Wikipedia] Shuwaikh Industrial Area Shuwaikh Industrial Area () is an area of Kuwait City in Kuwait. It comprises three separate districts: Shuwaikh Industrial-1, Shuwaikh Industrial-2, and Shuwaikh Industrial-3. The industrial area is also located nearby to Shuwaikh proper, Shuwaikh Port, Shuwaikh Commercial Area...
null
null
null
null
Using a dictionary, store the given student's name and marks as key value pairs.
name = "John Doe" marks = { "maths" : 90, "physics" : 80, "chemistry" : 85 }
student_data = {} student_data[name] = marks
null
Develop a Python program to generate a list with numbers in range 3 to 12.
# Generate a list with numbers in range 3 to 12 my_list = list(range(3, 13)) print(my_list) # [3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
null
Write a SQL statement that returns the average age of people in the table.
SELECT AVG(age) FROM people;
null
Create a list comprehension in Python to double each element in the list.
list = [1, 2, 3, 4, 5]
result = [x*2 for x in list]
null
How can you access the last element of the following Python array?
arr = ["A","B","C","D","E"]
arr[-1]
[HI Wikipedia] दक्षिण एशिया दक्षिण एशिया एक अनौपचारिक शब्दावली है जिसका प्रयोग एशिया महाद्वीप के दक्षिणी भाग के लिये किया जाता है। सामान्यतः इस शब्द से आशय हिमालय के दक्षिणवर्ती देशों से होता है। भारत, पाकिस्तान, श्री लंका और बांग्लादेश को दक्षिण एशिया के देश या भारतीय उपमहाद्वीप के देश कहा जाता है जिसमें नेपाल और भूट...
null
null
null
[EN Wikipedia] Abraham Cykiert Abraham Cykiert (26 April 1926 – 6 March 2009) was an Australian Holocaust survivor and Melburnian playwright and Zionist activist of the 1970s. Abraham Cykiert was born 26 April 1926 in Łódź, Second Polish Republic. As a child, he was forced to live in Łódź Ghetto during the German occu...
null
null
null
null
Create a function that returns the sum of all elements in a given array of numbers.
def array_sum(arr): sum = 0 for num in arr: sum += num return sum
null
Create a Python program that takes in a list of strings, sorts them, and then prints each string in sorted order.
["banana", "apple", "orange", "pear"]
def sortStrings(arr): arr.sort() for string in arr: print(string) #Test arr = ["banana", "apple", "orange", "pear"] sortStrings(arr) # Outputs: apple banana orange pear
[HI Wikipedia] भारतीय डाक भारतीय डाक सेवा () भारत सरकार द्वारा संचालित डाकसेवा है जो ब्रांड नाम के तौर पर इंडिया पोस्ट या भारतीय डाक के नाम से काम करती है। सैकड़ों साल से जारी सफर भारतीय डाक प्रणाली का जो उन्नत और परिष्कृत स्वरूप आज हमारे सामने है, वह हजारों सालों के लंबे सफर की देन है। अंग्रेजों ने डेढ़ सौ साल पहले अ...
null
null
null
null
Given a matrix, write a program to traverse it spirally.
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
def spiral_traverse(arr): res = [] top_row, bottom_row = 0, len(arr) - 1 left_col, right_col = 0, len(arr[0]) - 1 while top_row <= bottom_row and left_col <= right_col: for i in range(left_col, right_col + 1): res.append(arr[top_row][i]) top_row += 1 for i in range(top_row, bottom_row + 1): res.append(arr[i][right_col]...
null
Create a Python function called `fitForecast` that takes in the following parameters: * `y` (pandas DataFrame): A pandas DataFrame of the time series to be forecasted. The first column should be the date or time period, and the remaining columns should be the time series data. * `h` (int): The number of periods ahead t...
# -*- coding: utf-8 -*- """ Name: fitForecast.py Author: Collin Rooney Last Updated: 7/18/2017 This script will contain functions for all types of hierarchical modeling approaches. It will use the prophet package as a forecasting tool. The general idea of it is very similar to the hts package in R, but it is a little m...
null
Rewrite the following Python code to make it run at least 30% faster.
def binary_search(arr, x): left = 0 right = len(arr) - 1 while left <= right: mid = (left + right)//2 if arr[mid] == x: return mid elif arr[mid] < x: left = mid + 1 else: right = mid - 1 return -1
def binary_search(arr, x): left = 0 right = len(arr) - 1 while left <= right: mid = left + (right - left)//2 if arr[mid] == x: return mid elif arr[mid] < x: left = mid + 1 else: right = mid - 1 return -1
[EN Wikipedia] Ancient Egypt Ancient Egypt was a civilization in Northeast Africa situated in the Nile Valley. Ancient Egyptian civilization followed prehistoric Egypt and coalesced around 3100BC (according to conventional Egyptian chronology) with the political unification of Upper and Lower Egypt under Menes (often ...
null
null
null
null
Rewrite the following python code using a lambda expression
def function_name(x): return x * 2
function_name = lambda x: x * 2