code-rag-bench/online-tutorials huggingface dataset:
Construct a Diagonal Matrix in R Programming – diag() Function

01 Sep, 2021
diag() function in R Language is used to construct a diagonal matrix. 
Syntax: diag(x, nrow, ncol)Parameters: x: value present as the diagonal elements. nrow, ncol: number of rows and columns in which elements are represented.  
Example 1:  
Python3
# R program to illustrate# diag function # Calling the diag() function with# some number which will act as# rows as well as columns numberdiag(3)diag(5)
Output:  
     [, 1] [, 2] [, 3]
[1, ]    1    0    0
[2, ]    0    1    0
[3, ]    0    0    1

     [, 1] [, 2] [, 3] [, 4] [, 5]
[1, ]    1    0    0    0    0
[2, ]    0    1    0    0    0
[3, ]    0    0    1    0    0
[4, ]    0    0    0    1    0
[5, ]    0    0    0    0    1
Example 2:  
Python3
# R program to illustrate# diag function # Calling the diag() functiondiag(5, 2, 3)diag(10, 3, 3)
Output:  
     [, 1] [, 2] [, 3]
[1, ]    5    0    0
[2, ]    0    5    0

     [, 1] [, 2] [, 3]
[1, ]   10    0    0
[2, ]    0   10    0
[3, ]    0    0   10
 
gulshankumarar231
R Matrix-Function
R Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
LocalDateTime toLocalDate() method in Java with Examples

30 Nov, 2018
The toLocalDate() method of LocalDateTime class is used to get the LocalDate representation of this LocalDateTime. This method is derived from the Object Class and behaves in the similar way.
Syntax:
public LocalDate toLocalDate()
Parameter: This method takes no parameters.
Returns: This method returns a LocalDate value which is the LocalDate representation of this LocalDateTime.
Below programs illustrate the LocalDateTime.toLocalDate() method:
Program 1:
// Program to illustrate the toLocalDate() method  import java.util.*;import java.time.*;  public class GfG {    public static void main(String[] args)    {          // Get the LocalDateTime instance        LocalDateTime dt = LocalDateTime.now();          // Get the LocalDate representation of this LocalDateTime        // using toLocalDate() method        System.out.println(dt.toLocalDate());    }}
2018-11-30

Program 2:
// Program to illustrate the toLocalDate() method  import java.util.*;import java.time.*;  public class GfG {    public static void main(String[] args)    {          // Get the LocalDateTime instance        LocalDateTime dt            = LocalDateTime                  .parse("2018-11-03T12:45:30");          // Get the LocalDate representation of this LocalDateTime        // using toLocalDate() method        System.out.println(dt.toLocalDate());    }}
2018-11-03

Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDateTime.html#toLocalDate()
Java-Functions
Java-LocalDateTime
Java-time package
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Put Count and Percentage in One Cell in Excel? - GeeksforGeeks

09 Dec, 2021
In the real world, sometimes the user would like to present two or more values in a single cell. For eg in the sales report, we might need sales and the respective %share in the same cell. So in this article, we will learn how to display count and percentage in the same cell with the help of an example. In the below, sample data, have given sales data in $ and market share in Percentages. We need to add a column to show both Sales $ (Share %) in a cell as in (Img2).
Sample Data:
Sample Data
Output:
Expected Output
So to do this task, we use the following methods:
1. CONCAT() Function: CONCAT function is an Excel built-in function and allows to join 2 or more text/strings. Or we can say it joins two or more cells in a single content. This function must contain at least one text as an argument and if any of the arguments in the function is invalid then it will return an error.
Syntax:
CONCAT(text1, [text2],...)
Example: When we execute CONCAT(“geeks”, “-“, “for”, “-“, “geeks”) we get geeks-for-geeks as a output.
2. TEXT() function: The TEXT function is also an Excel built-in function and returns a text with a specified format. It is useful when you want to combine text or symbols or when you want to display numbers in a more readable form.
Syntax:
TEXT(value, format_text)
Here, the value parameter is used to convert to text, and the format_text parameter is used to format to apply the result.
Example: When we execute this TEXT(1000, “$0”) we get $1000 as an output.
Now follow the following steps to put count and percentage in one cell:
Step 1: Type column header “ $ Sales ( % Share)”  in cell E2.
Step 2: We use the Excel TEXT() function to retain excel format and the CONCAT() function to join four texts.
Text 1 – Sales $  
Text 2 – Open bracket
Text 3 – Share %
Text 4 – Close bracket
Type the formula in cell “E3” 
=CONCAT(TEXT(C3,"$ 0")," (", TEXT(D3,"0.0%"),")")
Step 3: Drag formula E3 to E8 to fill the same formula to all other cells
This is how we can easily put count and percentage in one cell.
Excel-functions
Picked
Excel
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Use Solver in Excel?
How to Find the Last Used Row and Column in Excel VBA?
How to Sum Values Based on Criteria in Another Column in Excel?
Introduction to Excel Spreadsheet
Macros in Excel
How to Read Data From Text File in Excel VBA?
How to Show Percentages in Stacked Column Chart in Excel?
How to Get Length of Array in Excel VBA?
How to Remove Duplicates From Array Using VBA in Excel?
Excel Dynamic Chart Linked with a Drop-down List
How to compute numerical negative value for all elements in a given NumPy array? - GeeksforGeeks

07 Aug, 2021
In this article, we will see how to compute the negative value for all elements in a given NumPy array. So, The negative value is actually the number which when added to any number becomes 0. 
Example: 
If we take a number as 4 then -4 is its negative number because when we add -4 to 4 we get sum as 0. Now let us take another example, Suppose we take a number -6 Now when we add +6 to it then the sum becomes zero. hence +6 is the negative value of -6. Now suppose we have an array of numbers:  
A = [1,2,3,-1,-2,-3,0]
So, the negative value of A is 
A'=[-1,-2,-3,1,2,3,0].
So, for finding the numerical negative value of an element we have to use numpy.negative() function of NumPy library.
Syntax: numpy.negative(arr, /, out=None, *, where=True, casting=’same_kind’, order=’K’, dtype=None, subok=True[, signature, extobj], ufunc ‘negative’)
Return: [ndarray or scalar] Returned array or scalar = -(input arr or scalar )
Now, let’s see the examples:
Example 1:
Python3
# importing libraryimport numpy as np # creating a arrayx = np.array([-1, -2, -3,              1, 2, 3, 0]) print("Printing the Original array:",      x) # converting array elements to# its corresponding negative valuer1 = np.negative(x) print("Printing the negative value of the given array:",      r1)
 Output:
Printing the Original array: [-1 -2 -3  1  2  3  0] 
Printing the negative value of the given array: [ 1  2  3 -1 -2 -3  0] 
 
Example 2:
Python3
# importing libraryimport numpy as np # creating a numpy 2D arrayx = np.array([[1, 2],              [2, 3]]) print("Printing the Original array Content:\n",      x) # converting array elements to# its corresponding negative valuer1 = np.negative(x) print("Printing the negative value of the given array:\n",      r1)
 Output: 
Printing the Original array Content:
[[1 2]
[2 3]]
Printing the negative value of the given array:
[[-1 -2]
[-2 -3]]
 
surinderdawra388
sumitgumber28
Python numpy-Mathematical Function
Python-numpy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Read a file line by line in Python
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
Iterate over a list in Python
*args and **kwargs in Python
Reading and Writing to text files in Python
Create a Pandas DataFrame from Lists
Check if element exists in list in Python
Calculating the balance factor in a Javascript AVL Tree

AVL tree checks the height of the left and the right sub-trees and assures that the difference is not more than 1. This difference is called the Balance Factor.
For example, in the following trees, the first tree is balanced and the next two trees are not balanced −
In the second tree, the left subtree of C has height 2 and the right subtree has height 0, so the difference is 2. In the third tree, the right subtree of A has height 2 and the left is missing, so it is 0, and the difference is 2 again. AVL tree permits difference (balance factor) to be only 1.
BalanceFactor = height(left-sutree) − height(right-sutree)
If the difference in the height of left and right sub-trees is more than 1, the tree is balanced using some rotation techniques.
Let us define this method and initialize the class as well − 
class AVLTree {
   constructor() {
      // Initialize a root element to null.
      this.root = null;
   }
   getBalanceFactor(root) {
      return this.getHeight(root.left) - this.getHeight(root.right);
   }
   getHeight(root) {
      let height = 0;
      if (root === null) {
         height = -1;
      } else {
         height = Math.max(this.getHeight(root.left), this.getHeight(root.right)) + 1;
      }
      return height;
   }
}
AVLTree.prototype.Node = class {
   constructor(data, left = null, right = null) {
      this.data = data;
      this.left = left;
      this.right = right;
   }
};
Python program to print duplicates from a list of integers?

Here we are trying to print all the duplicate numbers from a list of numbers. So, we are trying to print all the numbers which occur more than once in a list (not unique in the list).
Input: given_list = [ 3, 6, 9, 12, 3, 30, 15, 9, 45, 36, 12]
Output: desired_output = [3, 9, 12]
Input: given_list = [-27, 4, 29, -27, -2 , -99, 123, 499, -99]
Output: desired_output = [-27, -99]
Below is the code to find the duplicates elements from a given list −
 Live Demo
lst = [ 3, 6, 9, 12, 3, 30, 15, 9, 45, 36, 12, 12]
dupItems = []
uniqItems = {}
for x in lst:
   if x not in uniqItems:
      uniqItems[x] = 1
   else:
      if uniqItems[x] == 1:
         dupItems.append(x)
      uniqItems[x] += 1
print(dupItems)
[3, 9, 12]
Above program will work not only for a list of integers but others too −
Input: given_list = ['abc','def','raj','zack','abc','raj']
Output: output_returned= ['abc', 'raj']
The import Statements in Python

You can use any Python source file as a module by executing an import statement in some other Python source file.
The import has the following syntax −
import module1[, module2[,... moduleN]
When the interpreter encounters an import statement, it imports the module if the module is present in the search path. A search path is a list of directories that the interpreter searches before importing a module. For example, to import the module support.py, you need to put the following command at the top of the script −
#!/usr/bin/python
# Import module support
import support
# Now you can call defined function that module as follows
support.print_func("Zara")
When the above code is executed, it produces the following result −
Hello : Zara
A module is loaded only once, regardless of the number of times it is imported. This prevents the module execution from happening over and over again if multiple imports occur.
Python's from statement lets you import specific attributes from a module into the current namespace. The from...import has the following syntax −
from modname import name1[, name2[, ... nameN]]
For example, to import the function fibonacci from the module fib, use the following statement −
from fib import fibonacci
This statement does not import the entire module fib into the current namespace; it just introduces the item fibonacci from the module fib into the global symbol table of the importing module.
It is also possible to import all names from a module into the current namespace by using the following import statement −
from modname import *
This provides an easy way to import all the items from a module into the current namespace; however, this statement should be used sparingly.
Program to check whether two string arrays are equivalent or not in Python

Suppose we have two string type arrays word1 and word2, we have to check whether the two arrays represent the same string or not. We can say a string can be represented by an array if the elements in that array are concatenated in order forms the string.
So, if the input is like word1 = ["ko", "lka", "ta"] word2 = ["k", "olk", "at", "a"], then the output will be True as both are forming "kolkata".
To solve this, we will follow these steps −
s1:= blank string, s2:= blank string
s1:= blank string, s2:= blank string
for each string i in word1, dos1 := s1 concatenate i
for each string i in word1, do
s1 := s1 concatenate i
s1 := s1 concatenate i
for each string i in word2, dos2 := s2 + i
for each string i in word2, do
s2 := s2 + i
s2 := s2 + i
return true if s1 is same as s2, otherwise false
return true if s1 is same as s2, otherwise false
Let us see the following implementation to get better understanding −
 Live Demo
def solve(word1, word2):
   s1=''
   s2=''
   for i in word1:
      s1+=i
   for i in word2:
      s2+=i
   return (s1==s2)

word1 = ["ko", "lka", "ta"]
word2 = ["k", "olk", "at", "a"]
print(solve(word1, word2))
["ko", "lka", "ta"], ["k", "olk", "at", "a"]
True
How to remove outliers from multiple boxplots created with the help of boxplot function for columns of a data frame using single line code in R?

A data frame can have multiple numerical columns and we can create boxplot for each of the columns just by using boxplot function with data frame name but if we want to exclude outliers then outline argument can be used. For example, if we have a data frame df with multiple numerical columns that contain outlying values then the boxplot without outliers can be created as boxplot(df,outline=FALSE).
Consider the below data frame:
 Live Demo
set.seed(151)
x1<-c(-5,rnorm(18),5)
x2<-c(-6,rnorm(18,1,0.2),6)
x3<-c(-10,rnorm(18,1,0.5),10)
x4<-c(-12,rnorm(18,1,0.1),12)
x5<-c(-15,rnorm(18,1,0.8),15)
df<-data.frame(x1,x2,x3,x4,x5)
df
        x1          x2          x3       x4          x5
1 -5.00000000 -6.0000000 -10.0000000 -12.0000000 -15.0000000
2 -0.05153895 1.1347052  1.7228397    1.0216649    0.5526645
3 0.76573738  1.0620079  1.1305064    1.0407813    1.2837024
4 -0.14673959 0.7255857  1.9645730    0.9528957    0.9981142
5 -0.11318581 0.6726474  0.7000570    0.9979680    1.4502265
6 -0.39551140 0.9280697  1.0449886    0.9596063    1.1528738
7 0.78227595  1.2402230  1.2416571    1.0422124    0.8461499
8 -1.39747811 0.8708252  2.0122390    0.8796052    0.7642688
9 -1.01883832 0.8978782  1.8157587    0.8944016    0.3106157
10 0.22947586 0.8801754  1.6851877    1.0137921    2.2427285
11 0.67217297 1.1091206 -0.2065685    0.9715086    0.7642430
12 -0.48455178 0.9017412 0.5728289    1.0170325    2.6194087
13 0.56060896 1.0383071  1.2811840    0.9864194    2.3656720
14 0.06615648 0.8882945  0.8173998    0.8232215    1.4163186
15 -1.34987612 1.1845399 0.8286647    0.7985602    1.0698010
16 -0.24291581 1.2307996 0.6122296    1.0941148    1.3163952
17 -1.23674102 0.7255179 0.9935761    0.9278766    1.8420136
18 -1.47467765 1.2580363 1.3498465    0.9826864    1.0976992
19 2.43715892  1.2309804 1.0159605    0.8997847    0.9828209
20 5.00000000  6.0000000 10.0000000   12.0000000   15.0000000
Creating boxplot for columns of df −
boxplot(df)
Creating boxplot for columns of df without outliers −
boxplot(df,outline=FALSE)
4 Bit Binary Decrementer - GeeksforGeeks

05 May, 2021
What is 4 Bit Binary Decrementer ?It subtracts 1 binary value from the existing binary value stored in the register or in other words we can simply say that it decreases the existing value stored in the register by 1. For any n- bit binary decrementer, ‘n’ refers to the storage capacity of the register which needs to be decremented by 1. So we require ‘n’ number of full adders. Thus, in case of 4 bit binary decrementer we require 4 full adders. 
Working:
It consists of 4 full adders, connected one after the other. Each full adder has 3 inputs (carry input, 1, A) and 2 outputs (carry output and S)
A full adder basic consist of 2 half adders and an OR gate.
The carry(C) from previous full adder is propagated to the next full adder. So carry output from one full adder becomes one of the three input of the next full adder.
It follows the concept of 2’s complement, so we take 1 as input in all 4 full adder as seen from the above diagram.
So we add 1111 in order to subtract 1.
Reason for adding 1111:
This is because our main motive is to subtract 1 which in 4 bit representation is 0001
Representing it in 1’s complement will give: 1110
Representing it in 2’s complement (adding 1 to 1’s complement) will give: 1111
This is the reason why input 1111 is given to get a decremented output in 4 bit binary decrementer. 
    In 4 bit representation           In 1's complement           In 2's complement   
 1 -------------------------> 0001 ----------------------> 1110 ---------------------> 1111
                                                                                                               
Example:
(Refer to the circuit diagram from right to left for better understanding)

1. Input: 1010  ----> After using 4 bit binary decrementer ----> Output: 1001
        
  1 0 1 0       (Comparing from the circuit 1 0 1 0 is A3, A2, A1, A0 respectively)
+ 1 1 1 1       (1 1 1 1 is added as seen in the diagram also, in each full adder 1 is taken as input)
  ________
  1 0 1 1       ( 1 0 1 1 , in the diagram are S3, S2, S1, S0 respectively)
  ________
  
2. Input: 0010  ----> After using 4 bit binary decrementer ----> Output: 0001

   1 0 1 0 
 + 1 1 1 1
   ________
   0 0 0 1
   ________
   
3. Input: 0011  ----> After using 4 bit binary decrementer ----> Output: 0001

   0 0 1 1
 + 1 1 1 1
  _________
   0 0 1 0
  _________
  
Digital Electronics & Logic Design
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Magnitude Comparator in Digital Logic
4-bit binary Adder-Subtractor
Encoders and Decoders in Digital Logic
Difference between Flip-flop and Latch
BCD to 7 Segment Decoder
Differences between Synchronous and Asynchronous Counter
Carry Look-Ahead Adder
Encoder in Digital Logic
Difference between Feedback and Feed Forward control systems
Latches in Digital Logic
Count all possible paths from top left to bottom right of a mXn matrix in C++

In this tutorial, we will be discussing a program to find the number of possible paths from top left to bottom right of a mXn matrix.
For this we will be provided with a mXn matrix. Our task is to find all the possible paths from top left to bottom right of the given matrix.
#include <iostream>
using namespace std;
//returning count of possible paths
int count_paths(int m, int n){
   if (m == 1 || n == 1)
      return 1;
   return count_paths(m - 1, n) + count_paths(m, n - 1);
}
int main(){
   cout << count_paths(3, 3);
   return 0;
}
6
How to Convert Index to Column in Pandas Dataframe? - GeeksforGeeks

01 Jul, 2020
Pandas is a powerful tool which is used for data analysis and is built on top of the python library. The Pandas library enables users to create and manipulate dataframes (Tables of data) and time series effectively and efficiently. These dataframes can be used for training and testing machine learning models and Analyzing data. 
By default, each row of the dataframe has an index value. The rows in the dataframe are assigned index values from 0 to the (number of rows – 1) in a sequentially order with each row having one index value. There are many ways to convert an index to a column in a pandas dataframe. Let’s create a dataframe.
Python3
# importing the pandas library as pdimport pandas as pd    # Creating the dataframe dfdf = pd.DataFrame({'Roll Number': ['20CSE29', '20CSE49', '20CSE36', '20CSE44'],                   'Name': ['Amelia', 'Sam', 'Dean', 'Jessica'],                   'Marks In Percentage': [97, 90, 70, 82],                   'Grade': ['A', 'A', 'C', 'B'],                   'Subject': ['Physics', 'Physics', 'Physics', 'Physics']})  # Printing the dataframedf
Output:
Method 1: The simplest method is to create a new column and pass the indexes of each row into that column by using the Dataframe.index function.
Python3
import pandas as pd    df = pd.DataFrame({'Roll Number': ['20CSE29', '20CSE49', '20CSE36', '20CSE44'],                   'Name': ['Amelia', 'Sam', 'Dean', 'Jessica'],                   'Marks In Percentage': [97, 90, 70, 82],                   'Grade': ['A', 'A', 'C', 'B'],                   'Subject': ['Physics', 'Physics', 'Physics', 'Physics']})  # Printing the dataframedf['index'] = df.indexdf
Output:
Method 2: We can also use the Dataframe.reset_index function to convert the index as a column. The inplace parameter reflects the change in the dataframe to stay permanent.
Python3
import pandas as pd    df = pd.DataFrame({'Roll Number': ['20CSE29', '20CSE49', '20CSE36', '20CSE44'],                   'Name': ['Amelia', 'Sam', 'Dean', 'Jessica'],                   'Marks In Percentage': [97, 90, 70, 82],                   'Grade': ['A', 'A', 'C', 'B'],                   'Subject': ['Physics', 'Physics', 'Physics', 'Physics']})  # Printing the dataframedf.reset_index(level=0, inplace=True)df
Output:
Python pandas-dataFrame
Python-pandas
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
*args and **kwargs in Python
Reading and Writing to text files in Python
Create a Pandas DataFrame from Lists
Check if element exists in list in Python
How To Convert Python Dictionary To JSON?
Convert integer to string in Python
How to add a number to a current value in MySQL (multiple times at the same time)?

You can use UPDATE command for this.
The syntax is as follows
update yourTableName set yourColumnName =yourColumnName +yourIntegerValue where <yourCondition>;
To understand the above syntax, let us create a table. The query to create a table is as follows
mysql> create table addANumberToCurrentValueDemo
   -> (
   -> Game_Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> Game_Score int
   -> );
Query OK, 0 rows affected (0.67 sec)
Now you can insert some records in the table using insert command. The query is as follows −
mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(1090);
Query OK, 1 row affected (0.30 sec)
mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(204);
Query OK, 1 row affected (0.12 sec)
mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(510);
Query OK, 1 row affected (0.14 sec)
mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(7890);
Query OK, 1 row affected (0.14 sec)
mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(8999);
Query OK, 1 row affected (0.11 sec)
mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(1093859);
Query OK, 1 row affected (0.11 sec)
mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(157596);
Query OK, 1 row affected (0.11 sec)
mysql> insert into addANumberToCurrentValueDemo(Game_Score) values(4857567);
Query OK, 1 row affected (0.28 sec)
Now you can display all records from the table using select statement.
The query is as follows −
mysql> select *from addANumberToCurrentValueDemo;
The following is the output
+---------+------------+
| Game_Id | Game_Score |
+---------+------------+
|       1 | 1090       |
|       2 | 204        |
|       3 | 510        |
|       4 | 7890       |
|       5 | 9290       |
|       6 | 1093859    |
|       7 | 157596     |
|       8 | 4857567    |
+---------+------------+
8 rows in set (0.05 sec)
Here is the query to add a number to a current value in MySQL
mysql> update addANumberToCurrentValueDemo set Game_Score=Game_Score+11 where Game_Id=5;
Query OK, 1 row affected (0.15 sec)
Rows matched: 1 Changed: 1 Warnings: 0
Now check the table records once again to verify the column Game_Score has been updated from 8999 to 9010.
The query is as follows −
mysql> select *from addANumberToCurrentValueDemo;
The following is the output
+---------+------------+
| Game_Id | Game_Score |
+---------+------------+
|       1 | 1090       |
|       2 | 204        |
|       3 | 510        |
|       4 | 7890       |
|       5 | 9301       |
|       6 | 1093859    |
|       7 | 157596     |
|       8 | 4857567    |
+---------+------------+
8 rows in set (0.00 sec)
Python program to input a comma separated string - GeeksforGeeks

23 Jan, 2020
Given an input string that is comma-separated instead of space. The task is to store this input string in a list or variables. This can be achieved in Python using two ways:
Using List comprehension and split()
Using map() and split()
Method 1: Using List comprehension and split()
split() function helps in getting multiple inputs from the user. It breaks the given input by the specified separator. If the separator is not provided then any white space is used as a separator. Generally, users use a split() method to split a Python string but one can also use it in taking multiple inputs.
Example:
# Python program to take a comma# separated string as input    # Taking input when the numbers # of input are known and storing# in different variables  # Taking 2 inputsa, b = [int(x) for x in input("Enter two values\n").split(', ')]print("\nThe value of a is {} and b is {}".format(a, b))  # Taking 3 inputsa, b, c = [int(x) for x in input("Enter three values\n").split(', ')]print("\nThe value of a is {}, b is {} and c is {}".format(a, b, c))  # Taking multiple inputsL = [int(x) for x in input("Enter multiple values\n").split(', ')]print("\nThe values of input are", L) 
Output:
Enter two values
1, 2

The value of a is 1 and b is 2
Enter three values
1, 2, 3

The value of a is 1, b is 2 and c is 3
Enter multiple values
1, 22, 34, 6, 88, 2

The values of input are [1, 22, 34, 6, 88, 2]

Method 2: Using map() and split()
map() function returns a list of the results after applying the given function to each item of a given iterable (list, tuple etc.)
# Python program to take a comma# separated string as input    # Taking input when the numbers # of input are known and storing# in different variables  # Taking 2 inputsa, b = map(int, input("Enter two values\n").split(', '))print("\nThe value of a is {} and b is {}".format(a, b))  # Taking 3 inputsa, b, c = map(int, input("Enter three values\n").split(', '))print("\nThe value of a is {}, b is {} and c is {}".format(a, b, c))  # Taking multiple inputsL = list(map(int, input("Enter multiple values\n").split(', ')))print("\nThe values of input are", L)
Output:
Enter two values
1, 2

The value of a is 1 and b is 2
Enter three values
1, 2, 3

The value of a is 1, b is 2 and c is 3
Enter multiple values
1, 2, 3, 4

The values of input are [1, 2, 3, 4]

python-input-output
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Read a file line by line in Python
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
Python program to convert a list to string
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Split string into list of characters
Python | Convert a list to dictionary
Build your own barcode and QRcode scanner using python | by Pruthvi Hingu | Towards Data Science

Let’s create a program that scans the QR codes and Barcodes from an image. For this program, we need three packages, which are OpenCV, NumPy, and pyzbar. Most of the python programmers are familiar with OpenCV and Numpy libraries. OpenCV is an open-source computer vision and machine learning library. It is a useful library for image processing. We are using this library in our project for processing each frame from a video captured by a device. We are using Numpy here because pyzbar works with OpenCV / numpy ndarrays. Whereas, pyzbar library is used to read barcodes and QR codes from a given image. It supports EAN-13/UPC-A, UPC-E, EAN-8, Code 128, Code 39, Interleaved 2 of 5, and QR Code. So, this is a small introduction to our project and libraries. Install the required libraries using the following commands.
For OpenCV
pip install opencv-python
For pyzbar
pip install pyzbar
For Numpy
pip install numpy
Import all the required libraries for our program.
import cv2import numpy as npfrom pyzbar.pyzbar import decode
Capture the video from the device camera.
Now, let’s create a decoder function that decodes barcode and QR code from a given image.
This function takes an image, then identifies the QRcode and barcode from the image, and decodes the value of it. Here barcode is a list of barcode and QRcode objects recognized by the decode function. Each object contains rect, polygon, data, type, etc attributes. rect and polygon attributes give the position of barcode and QRcode.
Check the final program below.
Let’s check the output.
You can download the source code from Github.
github.com
Thanks for reading this piece. Hope to see you again in the next article! Please connect with me through LinkedIn:
Java program to reverse a string using recursion

Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function. You can reverse a string using the recursive function as shown in the following program.
Live Demo
public class StringReverse {
   public String reverseString(String str){
   
      if(str.isEmpty()){
         return str;
      } else {
         return reverseString(str.substring(1))+str.charAt(0);
      }
   }
   public static void main(String[] args) {
      StringReverse obj = new StringReverse();
      String result = obj.reverseString("Tutorialspoint");
      System.out.println(result);
   }
}
tniopslairotuT
How to select a date less than the current date with MySQL?

Let us first create a table −
mysql> create table DemoTable1877
   (
   DueDate datetime
   );
Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1877 values('2019-12-10');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1877 values('2019-12-05');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1877 values('2019-12-07');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1877 values('2019-12-09');
Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1877;
This will produce the following output −
+---------------------+
| DueDate             |
+---------------------+
| 2019-12-10 00:00:00 |
| 2019-12-05 00:00:00 |
| 2019-12-07 00:00:00 |
| 2019-12-09 00:00:00 |
+---------------------+
4 rows in set (0.00 sec)
The current date is as follows −
mysql> select curdate();
+------------+
| curdate()  |
+------------+
| 2019-12-08 |
+------------+
1 row in set (0.00 sec)
Here is the query to select a date less than the current one −
mysql> select * from DemoTable1877 where DueDate < now();
This will produce the following output −
+---------------------+
| DueDate             |
+---------------------+
| 2019-12-05 00:00:00 |
| 2019-12-07 00:00:00 |
+---------------------+
2 rows in set (0.00 sec)
What do you mean by buffer in C language?

A temporary storage area is called buffer. All input output (I/O) devices contain I/O buffer.
When we try to pass more than the required number of values as input then, the remaining values will automatically hold in the input buffer. This buffer data automatically go to the next input functionality, if it is exists.
We have to clear the buffer before the next input is taken in.
Following is the C program for buffer −
#include<stdio.h>
void main(){
   int a,b;
   printf("\n Enter a value: ");
   scanf("%d",&a);
   printf("\n Enter b value: ");
   scanf("%d",&b);
   printf("\n a+b=%d ",a+b);
   getch();
}
When the above program is executed, it produces the following result −
Enter a value: 1
Enter b value: 2
a+b=3
Again, run the program. This time, we try to enter values in a and not in b.
Enter a value: 1 2 3
Enter b value: a+b=3
Even though we didn’t enter b value, it takes the previously stored value, which is present in buffer already.
In the implementation, when we need to remove standard input buffer data then go for flushall() or fflush() function.
flushall() − It is a predefined function present in stdio.h. by using flushall we can remove the data from I/O buffer.
flushall() − It is a predefined function present in stdio.h. by using flushall we can remove the data from I/O buffer.
fflush() − It is a predefined function in "stdio.h" header file which is used to clear either input or output buffer memory.
fflush() − It is a predefined function in "stdio.h" header file which is used to clear either input or output buffer memory.
fflush(stdin) − It is used to clear the input buffer memory. It is recommended to use before writing scanf statement.
fflush(stdin) − It is used to clear the input buffer memory. It is recommended to use before writing scanf statement.
fflush(stdout) − It is used for clearing the output buffer memory. It is recommended to use before printf statement.
fflush(stdout) − It is used for clearing the output buffer memory. It is recommended to use before printf statement.
Garbage collection(GC) in JavaScript?

garbage collection (GC) is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program. The general problem of automatically finding whether some memory "is not needed anymore" is undecidable. As a consequence, garbage collectors implement a restriction of a solution to the general problem.
The main concept that garbage collection algorithms rely on is the concept of reference. Within the context of memory management, an object is said to reference another object if the former has access to the latter (either implicitly or explicitly).
let a = []
function addToA() {
   let x = {name: "John"}
   a.push(x)
}
console.log(a[0])
{name: "John"}
Note that x is not in scope anymore but is still accessible using a. This means that it needs to stay in memory until its reference is not there anymore. If we pop it from the array, it won't be needed anymore and can be garbage collected.
Garbage collectors work using following algorithms −
1. Reference-counting garbage collection − An object is said to be "garbage", or collectible if there are zero references pointing to it. This is used in older browsers. But this causes a problem with circular referencing objects as they cannot be collected(There is always a reference to them from the other object. )
2. Mark-and-sweep algorithm − This algorithm reduces the definition of "an object is no longer needed" to "an object is unreachable". This algorithm assumes the knowledge of a set of objects called roots. In JavaScript, the root is the global object. Periodically, the GC starts from these roots, find all objects that are referenced from these roots, recursively. Starting from the roots, the GC will thus find all reachable objects and collect all non-reachable objects.
You can read more about GC in javascript athttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management
Highcharts - Basic Pie Chart

Following is an example of a basic pie chart.
We have already seen the configuration used to draw a chart in Highcharts Configuration Syntax chapter.
An example of a basic pie chart is given below.
Let us now see the additional configurations/steps taken.
Configure the series type to be pie based. series.type decides the series type for the chart. Here, the default value is "line".
var series = {
   type: 'pie'
};
highcharts_pie_basic.htm
<html>
   <head>
      <title>Highcharts Tutorial</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
      <script src = "https://code.highcharts.com/highcharts.js"></script>  
   </head>
   
   <body>
      <div id = "container" style = "width: 550px; height: 400px; margin: 0 auto"></div>
      <script language = "JavaScript">
         $(document).ready(function() {
            var chart = {
               plotBackgroundColor: null,
               plotBorderWidth: null,
               plotShadow: false
            };
            var title = {
               text: 'Browser market shares at a specific website, 2014'   
            };
            var tooltip = {
               pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
            };
            var plotOptions = {
               pie: {
                  allowPointSelect: true,
                  cursor: 'pointer',
                  
                  dataLabels: {
                     enabled: true,
                     format: '<b>{point.name}%</b>: {point.percentage:.1f} %',
                     style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor)||
                        'black'
                     }
                  }
               }
            };
            var series = [{
               type: 'pie',
               name: 'Browser share',
               data: [
                  ['Firefox',   45.0],
                  ['IE',       26.8],
                  {
                     name: 'Chrome',
                     y: 12.8,
                     sliced: true,
                     selected: true
                  },
                  
                  ['Safari',    8.5],
                  ['Opera',     6.2],
                  ['Others',   0.7]
               ]
            }];
            var json = {};   
            json.chart = chart; 
            json.title = title;     
            json.tooltip = tooltip;  
            json.series = series;
            json.plotOptions = plotOptions;
            $('#container').highcharts(json);  
         });
      </script>
   </body>
   
</html>
Verify the result.
 Print
 Add Notes
 Bookmark this page
Python Number atan2() Method

Python number  method atan2() returns atan(y / x), in radians.
Following is the syntax for atan2() method −
atan2(y, x)

Note − This function is not accessible directly, so we need to import math module and then we need to call this function using math static object.
y − This must be a numeric value.
y − This must be a numeric value.
x − This must be a numeric value.
x − This must be a numeric value.
This method returns atan(y / x), in radians.
The following example shows the usage of atan2() method.
#!/usr/bin/python
import math

print "atan2(-0.50,-0.50) : ",  math.atan2(-0.50,-0.50)
print "atan2(0.50,0.50) : ",  math.atan2(0.50,0.50)
print "atan2(5,5) : ",  math.atan2(5,5)
print "atan2(-10,10) : ",  math.atan2(-10,10)
print "atan2(10,20) : ",  math.atan2(10,20)
When we run above program, it produces following result −
atan2(-0.50,-0.50) :  -2.35619449019
atan2(0.50,0.50) :  0.785398163397
atan2(5,5) :  0.785398163397
atan2(-10,10) :  -0.785398163397
atan2(10,20) :  0.463647609001


    187 Lectures 
     17.5 hours 

 Malhar Lathkar

    55 Lectures 
     8 hours 

 Arnab Chakraborty

    136 Lectures 
     11 hours 

 In28Minutes Official

    75 Lectures 
     13 hours 

 Eduonix Learning Solutions

    70 Lectures 
     8.5 hours 

 Lets Kode It

    63 Lectures 
     6 hours 

 Abhilash Nelson
 Print
 Add Notes
 Bookmark this page
RxJS - Join Operator merge

This operator will take in the input observable and will emit all the values from the observable and emit one single output observable.
merge(observable:array[]): Observable

observable − The input will be an array of Observable.
It will return an observable with a single value as output.
import { of, merge } from 'rxjs';
import { concat } from 'rxjs/operators';

let list1 = of(2, 3, 4, 5, 6);
let list2 = of(4, 9, 16, 25, 36)
let final_val = merge(list1, list2);
final_val.subscribe(x => console.log(x));

    51 Lectures 
     4 hours 

 Daniel Stern
 Print
 Add Notes
 Bookmark this page
How to use replaceAll () in Android textview?

This example demonstrate about How to use replaceAll () in Android textview.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.
Step 2 − Add the following code to res/layout/activity_main.xml.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical"
   android:gravity="center"
   tools:context=".MainActivity">
   <EditText
      android:id="@+id/name"
      android:layout_width="match_parent"
      android:hint="Enter name"
      android:layout_height="wrap_content" />
   <Button
      android:id="@+id/click"
      android:text="Click"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" />
   <TextView
      android:id="@+id/textview"
      android:layout_width="wrap_content"
      android:textSize="25sp"
      android:layout_height="wrap_content" />
</LinearLayout>
In the above code, we have taken name as Edit text, when user click on button it will take data and replace space with emptystring.
Step 3 − Add the following code to src/MainActivity.java
package com.example.myapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
   EditText name;
   Button button;
   TextView text;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      name = findViewById(R.id.name);
      button = findViewById(R.id.click);
      text = findViewById(R.id.textview);
      button.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            if (!name.getText().toString().isEmpty()) {
               if (name.getText().toString().length() >= 0) {
                  String replace = name.getText().toString().replaceAll("\\s","");
                  text.setText(String.valueOf(replace));
               }
            } else {
               name.setError("Plz enter name");
            }
         }
      });
   }
}
Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from android studio, open one of your project's activity files and click Run  icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen −
In the above result, enter the string as “Krishna sai sai” . It replaced all space with empty string value.
Click here to download the project code
Java String equalsIgnoreCase() Method with Examples - GeeksforGeeks

10 Nov, 2021
The equalsIgnoreCase() method of the String class compares two strings irrespective of the case (lower or upper) of the string. This method returns a boolean value, true if the argument is not null and represents an equivalent String ignoring case, else false.
Syntax: 
str2.equalsIgnoreCase(str1);
Note: Here str1 and str2 both are the strings that we need to compare.
Parameters: A string that is supposed to be compared.
Return Type: A boolean value, true if the argument is not null and it represents an equivalent String ignoring case, else false.
Illustrations: 
Input : str1 = "pAwAn";
        str2 = "PAWan"
        str2.equalsIgnoreCase(str1);
Output :true
Input : str1 = "powAn";
        str2 = "PAWan"
        str2.equalsIgnoreCase(str1);
Output :false
Explanation: powan and pawan are different strings. 
Note: str1 is a string that needs to be compared with str2.
Example:
Java
// Java Program to Illustrate equalsIgnoreCase() method // Importing required classesimport java.lang.*; // Main classpublic class GFG {     // Main driver method    public static void main(String[] args)    {         // Declaring and initializing strings to compare        String str1 = "GeeKS FOr gEEks";        String str2 = "geeKs foR gEEKs";        String str3 = "ksgee orF geeks";         // Comparing strings        // If we ignore the cases        boolean result1 = str2.equalsIgnoreCase(str1);         // Both the strings are equal so display true        System.out.println("str2 is equal to str1 = "                           + result1);         // Even if we ignore the cases        boolean result2 = str2.equalsIgnoreCase(str3);         // Both the strings are not equal so display false        System.out.println("str2 is equal to str3 = "                           + result2);    }}
str2 is equal to str1 = true
str2 is equal to str3 = false
nishkarshgandhi
sweetyty
solankimayank
Java-Functions
Java-lang package
Java-Strings
Java
Java-Strings
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Different ways of Reading a text file in Java
Constructors in Java
Stream In Java
Exceptions in Java
Generics in Java
Comparator Interface in Java with Examples
StringBuilder Class in Java with Examples
HashMap get() Method in Java
Functional Interfaces in Java
Strings in Java
C Program to display hostname and IP address - GeeksforGeeks

24 Nov, 2017
There are many ways to find Hostname and IP address of a local machine. Here is a simple method to find hostname and IP address using C program.
We will be using the following functions :-
gethostname() : The gethostname function retrieves the standard host name for the local computer.
gethostbyname() : The gethostbyname function retrieves host information corresponding to a host name from a host database.
inet_ntoa() : The inet_ntoa function converts an (Ipv4) Internet network address into an ASCII string in Internet standard dotted-decimal format.
C/C++
// C program to display hostname// and IP address#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <errno.h>#include <netdb.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>  // Returns hostname for the local computervoid checkHostName(int hostname){    if (hostname == -1)    {        perror("gethostname");        exit(1);    }}  // Returns host information corresponding to host namevoid checkHostEntry(struct hostent * hostentry){    if (hostentry == NULL)    {        perror("gethostbyname");        exit(1);    }}  // Converts space-delimited IPv4 addresses// to dotted-decimal formatvoid checkIPbuffer(char *IPbuffer){    if (NULL == IPbuffer)    {        perror("inet_ntoa");        exit(1);    }}  // Driver codeint main(){    char hostbuffer[256];    char *IPbuffer;    struct hostent *host_entry;    int hostname;      // To retrieve hostname    hostname = gethostname(hostbuffer, sizeof(hostbuffer));    checkHostName(hostname);      // To retrieve host information    host_entry = gethostbyname(hostbuffer);    checkHostEntry(host_entry);      // To convert an Internet network    // address into ASCII string    IPbuffer = inet_ntoa(*((struct in_addr*)                           host_entry->h_addr_list[0]));      printf("Hostname: %s\n", hostbuffer);    printf("Host IP: %s", IPbuffer);      return 0;}
Hostname: cContainer
Host IP: 10.98.162.101

Output varies machine to machine
C Language
C++
Computer Networks
Computer Networks
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Multidimensional Arrays in C / C++
rand() and srand() in C/C++
Command line arguments in C/C++
Core Dump (Segmentation fault) in C/C++
Left Shift and Right Shift Operators in C/C++
Vector in C++ STL
Inheritance in C++
Initialize a vector in C++ (6 different ways)
Map in C++ Standard Template Library (STL)
Multidimensional Arrays in C / C++