code-rag-bench/online-tutorials huggingface dataset:
Tk - Menu Widget

Tk menu widget is used along with Tk widget menubutton. So, we will see menubutton first. The syntax for menu button widget is shown below −
menubutton menubuttonName options

The options available for the menu button widget are listed below in the following table −
-command action
Sets the command action for button.
-text text
Sets the text for the widget.
-textvariable varName
Variable associated with the widget. When the text of widget changes, the variable is set to text of widget.
-width number
Sets the width for widget.
-menu menuName
Specifies the name of associated menu widget.
-underline charPosition
Sets the position for hotkey.
The syntax for menu is shown below −
menu menuName options

The options available for the menu widget are listed below in the following table −
-font fontDescriptor
Used to set font for widget.
-postcommand action
Sets the command action to be done before a menu is posted.
-menu menuName
Specifies the name of associated menu widget.
-tearoff boolean
Allows or disallows a menu to be removed from the menubutton and displayed in a permanent window. Default is enabled.
The syntax for adding menubutton is shown below −
menuName add type menubuttonType options

The type includes separator, cascade, checkbutton, radiobutton, and command.
The options available for the menuName add are listed below in table −
-command action
Sets the command action for the menubutton.
-menu menuName
Specifies the name of associated menu widget.
-label string
Set the text of the menu.
-variable varName
Sets the variable to be set when this entry is selected.
-value string
The value is set for the variable.
-underline position
Sets the position for hotkey.
A simple Tk menu is shown below −
#!/usr/bin/wish

menubutton .myMenubutton -menu .myMenubutton.myMenu -text "ChangeText"
menu .myMenubutton.myMenu
.myMenubutton.myMenu add command -label Hello -command {set myvariable "Hello"}
.myMenubutton.myMenu add command -label World -command {set myvariable "World"}
pack .myMenubutton
pack [label .myLabel  -text "Select An option" -font {Helvetica -18 bold} -height 5
   -width 15 -textvariable myvariable]
When we run the above program, we will get the following output −
When we select a menu option, we will get an output as shown below −
 Print
 Add Notes
 Bookmark this page
VBA - Instr

The InStr Function returns the first occurrence of one string within another string. The search happens from the left to the right.
InStr([start,]string1,string2[,compare])

Start − An optional parameter. Specifies the starting position for the search. The search begins at the first position from the left to the right.
Start − An optional parameter. Specifies the starting position for the search. The search begins at the first position from the left to the right.
String1 − A required parameter. String to be searched.
String1 − A required parameter. String to be searched.
String2 − A required parameter. String against which String1 is searched.
String2 − A required parameter. String against which String1 is searched.
Compare − An optional parameter. Specifies the string comparison to be used. It can take the following mentioned values.

0 = vbBinaryCompare - Performs Binary Comparison (Default)
1 = vbTextCompare - Performs Text Comparison


Compare − An optional parameter. Specifies the string comparison to be used. It can take the following mentioned values.
0 = vbBinaryCompare - Performs Binary Comparison (Default)
0 = vbBinaryCompare - Performs Binary Comparison (Default)
1 = vbTextCompare - Performs Text Comparison
1 = vbTextCompare - Performs Text Comparison
Add a button and add the following function.
Private Sub Constant_demo_Click() 
   Dim Var As Variant 
   Var = "Microsoft VBScript" 
   MsgBox ("Line 1 : " & InStr(1, Var, "s")) 
   MsgBox ("Line 2 : " & InStr(7, Var, "s")) 
   MsgBox ("Line 3 : " & InStr(1, Var, "f", 1)) 
   MsgBox ("Line 4 : " & InStr(1, Var, "t", 0)) 
   MsgBox ("Line 5 : " & InStr(1, Var, "i")) 
   MsgBox ("Line 6 : " & InStr(7, Var, "i")) 
   MsgBox ("Line 7 : " & InStr(Var, "VB")) 
End Sub 
When you execute the above function, it produces the following output.
Line 1 : 6
Line 2 : 0
Line 3 : 8
Line 4 : 9
Line 5 : 2
Line 6 : 16
Line 7 : 11


    101 Lectures 
     6 hours 

 Pavan Lalwani

    41 Lectures 
     3 hours 

 Arnold Higuit

    80 Lectures 
     5.5 hours 

 Prashant Panchal

    25 Lectures 
     2 hours 

 Prashant Panchal

    26 Lectures 
     2 hours 

 Arnold Higuit

    92 Lectures 
     10.5 hours 

 Vijay Kumar Parvatha Reddy
 Print
 Add Notes
 Bookmark this page
C++ Program to Concatenate Two Strings

A string is a one dimensional character array that is terminated by a null character. Concatenation of two strings is the joining of them to form a new string. For example.
String 1: Mangoes are
String 2: tasty
Concatenation of 2 strings: Mangoes are tasty
A program to concatenate two strings is given as follows.
 Live Demo
#include <iostream>
using namespace std;
int main() {
   char str1[100] = "Hi...";
   char str2[100] = "How are you";
   int i,j;
   cout<<"String 1: "<<str1<<endl;
   cout<<"String 2: "<<str2<<endl;
   for(i = 0; str1[i] != '\0'; ++i);
   j=0;
   while(str2[j] != '\0') {
      str1[i] = str2[j];
      i++;
      j++;
   }
   str1[i] = '\0';
   cout<<"String after concatenation: "<<str1;
   return 0;
}
String 1: Hi...
String 2: How are you
String after concatenation: Hi...How are you
In the above program, there are two strings str1 and str2. A for loop is used to reach the end of str1. At the end of the for loop, i contains the index of the null value in the str1. The following code snippet demonstrates this.
for(i = 0; str1[i] != '\0'; ++i);
A while loop is used to transfer the value of str2 to str1. Variable j starts from 0 and copies the character in str2 into str1 at the position pointed by i. This loop runs till value of str2[j] is not null. This is demonstrated as follows.
j=0;
while(str2[j] != '\0') {
   str1[i] = str2[j];
   i++;
   j++;
}
After the strings are concatenated in str1, null is added to the end. Then the concatenated string is displayed. The code snippet for this is as follows −
str1[i] = '\0';
cout<<"String after concatenation: "<<str1;
AWK - Relational Operators

AWK supports the following relational operators −
It is represented by ==. It returns true if both operands are equal, otherwise it returns false. The following example demonstrates this −
awk 'BEGIN { a = 10; b = 10; if (a == b) print "a == b" }'
On executing this code, you get the following result −
a == b

It is represented by !=. It returns true if both operands are unequal, otherwise it returns false.
[jerry]$ awk 'BEGIN { a = 10; b = 20; if (a != b) print "a != b" }'
On executing this code, you get the following result −
a != b

It is represented by <. It returns true if the left-side operand is less than the right-side operand; otherwise it returns false.
[jerry]$ awk 'BEGIN { a = 10; b = 20; if (a < b) print "a  < b" }'
On executing this code, you get the following result −
a < b

It is represented by <=. It returns true if the left-side operand is less than or equal to the right-side operand; otherwise it returns false.
[jerry]$ awk 'BEGIN { a = 10; b = 10; if (a <= b) print "a <= b" }'
On executing this code, you get the following result −
a <= b

It is represented by >. It returns true if the left-side operand is greater than the right-side operand, otherwise it returns false.
[jerry]$ awk 'BEGIN { a = 10; b = 20; if (b > a ) print "b > a" }'
On executing the above code, you get the following result −
b > a

It is represented by >=. It returns true if the left-side operand is greater than or equal to the right-side operand; otherwise it returns false.
b >= a

 Print
 Add Notes
 Bookmark this page
How to write a recursive function in Python?

A recursive function is a function that calls itself during its execution. This enables the function to repeat itself several times, outputting the result and the end of each iteration. Recursion has something to do with infinity. 
Following is an example of recursive function to find the factorial of an integer.
Factorial of a number is the product of all the integers from 1 to that number. 
For example, the factorial of 9 (denoted as 9!) is 1*2*3*4*5*6*7*8*9 = 362880.
def factorial(i):
   if i == 1:
      return 1
   else:
      return (i * factorial(i-1))
number = 9
print("The factorial of", number, "is", factorial(number))
The factorial of 9 is 362880
In the above program factorial() is a recursive functions as it calls itself. Each function call multiples the number with the factorial of number 1 until the number is equal to one.
For example to place two parallel mirrors facing each other. Any object in between them would be reflected recursively.
def Function(x):
   if (x < 1):
      return
   else:
      print( x,end = " ")
      Function(x-1)
      print(x,end = " ")
      return
x = 5
Function(x)
5 4 3 2 1 1 2 3 4 5
Matplotlib.figure.Figure.clf() in Python - GeeksforGeeks

30 Apr, 2020
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements.
The clf() method of figure module of matplotlib library is used to Clear the figure.
Syntax: clf(self, keep_observers=False)
Parameters: This accept the following parameters that are described below:
keep_observers: This parameter is the boolean value.
Returns: This method does not return any value.
Below examples illustrate the matplotlib.figure.Figure.clf() function in matplotlib.figure:
Example 1:
# Implementation of matplotlib functionimport numpy as npimport matplotlib.pyplot as plt      fig, ax = plt.subplots()  ax.set_xlabel('x-axis')ax.set_ylabel('y-axis')  ax.plot([1, 2, 3])ax.grid(True)  fig.clf(True)   fig.suptitle('matplotlib.figure.Figure.clf() \function Example\n\n', fontweight ="bold")  plt.show()
Output:
Example 2:
# Implementation of matplotlib functionimport numpy as npimport matplotlib.pyplot as plt      t = np.linspace(0.0, 2.0, 201)s = np.sin(2 * np.pi * t)   fig, [ax, ax1] = plt.subplots(2, 1, sharex = True)   ax.set_ylabel('y-axis')ax.plot(t, s)ax.grid(True)ax.set_title('Sample Example',             fontsize = 12,             fontweight ='bold')   ax1.set_ylabel('y-axis')ax1.plot(t, s)ax1.grid(True)  fig.clf(False)   fig.suptitle('matplotlib.figure.Figure.clf() \function Example\n\n', fontweight ="bold")  plt.show()
Output:
Matplotlib figure-class
Python-matplotlib
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Check if element exists in list in Python
How To Convert Python Dictionary To JSON?
How to drop one or multiple columns in Pandas Dataframe
Defaultdict in Python
Python Classes and Objects
Create a directory in Python
Python | os.path.join() method
Python | Pandas dataframe.groupby()
Python | Get unique values from a list
Batch Script - MD

This batch command creates a new directory in the current location.
md [new directory name]

@echo off 
md newdir 
cd newdir 
cd Rem “Goes back to the parent directory and create 2 directories” 
cd.. 
md newdir1 newdir1 
cd newdir1 
cd 
cd.. 
cd newdir2 
cd
The above command produces the following output.
C:\newdir 
C:\newdir1 
C:\newdir2

 Print
 Add Notes
 Bookmark this page
bzgrep command in Linux with examples - GeeksforGeeks

15 May, 2019
bzgrep is a Linux command used to search for a pattern or an expression but inside a bzip2-compressed file. This command simply passes it’s arguments and the decompressed files to grep. Therefore, all the flags used in the grep command remain same in bzgrep, since they are simply sent to grep as they are. If no file is specified, then the standard input is decompressed if necessary and fed to grep.
Synopsis:
bzgrep [ grep_options ] [ -e ] pattern filename...

Example: Here we take a normal text file, use grep on it. Then we compress it using bzip2 and search the specific pattern in the compressed file with bzgrep.
linux-command
Linux-file-commands
Picked
Technical Scripter 2018
Linux-Unix
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Thread functions in C/C++
Basic Operators in Shell Scripting
nohup Command in Linux with Examples
Array Basics in Shell Scripting | Set 1
chown command in Linux with Examples
mv command in Linux with examples
Named Pipe or FIFO with example C program
SED command in Linux | Set 2
scp command in Linux with Examples
Docker - COPY Instruction
How to replace multiple spaces in a string using a single space using Java regex?

The metacharacter “\\s” matches spaces and + indicates the occurrence of the spaces one or more times, therefore, the regular expression \\S+ matches all the space characters (single or multiple). Therefore, to replace multiple spaces with a single space.
Match the input string with the above regular expression and replace the results with single space “ ”.
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ReplaceAllExample {
   public static void main(String args[]) {
      //Reading String from user
      System.out.println("Enter a String");
      Scanner sc = new Scanner(System.in);
      String input = sc.nextLine();
      String regex = "\\s+";
      //Compiling the regular expression
      Pattern pattern = Pattern.compile(regex);
      //Retrieving the matcher object
      Matcher matcher = pattern.matcher(input);
      //Replacing all space characters with single space
      String result = matcher.replaceAll(" ");
      System.out.print("Text after removing unwanted spaces: \n"+result);
   }
}
Enter a String
hello this is a sample text with irregular spaces
Text after removing unwanted spaces:
hello this is a sample text with irregular spaces
import java.util.Scanner;
public class Test {
   public static void main(String args[]) {
      //Reading String from user
      System.out.println("Enter a String");
      Scanner sc = new Scanner(System.in);
      String input = sc.nextLine();
      //Regular expression to match space(s)
      String regex = "\\s+";
      //Replacing the pattern with single space
      String result = input.replaceAll(regex, " ");
      System.out.print("Text after removing unwanted spaces: \n"+result);
   }
}
Enter a String
hello this is a sample text with irregular spaces
Text after removing unwanted spaces:
hello this is a sample text with irregular spaces
Ext.js - Ext.panel.Panel Container

Ext.panel.Panel: It is the basic container which allows to add items in a normal panel.
Following is the simple syntax to create Ext.panel.Panel container.
Ext.create('Ext.panel.Panel', {
   items: [child1, child2]   
   // this way we can add different child elements to the container as container items.
});

Following is a simple example showing Ext.panel.Panel Container.
<!DOCTYPE html>
<html>
   <head>
      <link href = "https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/theme-classic/resources/theme-classic-all.css" 
         rel = "stylesheet" />
      <script type = "text/javascript" 
         src = "https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/ext-all.js"></script>
      
      <script type = "text/javascript">
         Ext.onReady(function () {
            var childPanel1 = Ext.create('Ext.Panel', {
               html: 'First Panel'
            });
            var childPanel2 = Ext.create('Ext.Panel', {
               html: 'Another Panel'
            });
            Ext.create('Ext.panel.Panel', {
               renderTo: Ext.getBody(),
               width: 100,
               height : 100,
               border : true,
               frame : true,
               items: [ childPanel1, childPanel2 ]
            });
         });
      </script>
   </head>
   
   <body>
   </body>
</html>
The above program will produce the following result −
 Print
 Add Notes
 Bookmark this page
Get a substring of specified length from a string in Julia - SubString() Method - GeeksforGeeks

26 Mar, 2020
The SubString() is an inbuilt function in julia which is used to return a part of the specified parent string s within range i:j or r, where i, j and r is given as the parameter.
Syntax:SubString(string::AbstractString, i::Integer, j::Integer)orSubString(string::AbstractString, r::UnitRange)
Parameters:
string: Specified parent string
i: Specified starting index
j: Specified last index
r: Specified unit range
Returns: It returns a part of the specified parent string s within range i:j or r, where i, j and r is given as the parameter.
Example 1:
# Julia program to illustrate # the use of String SubString() method  # Finding a part of the parent string# "Geeks" from starting index 1# to ending index 3println(SubString("Geeks", 1, 3))  # Finding a part of the parent string# "GeeksforGeeks" from starting index 5# to ending index 10println(SubString("GeeksforGeeks", 5, 10))  # Finding a part of the parent string# "Geeks" with unitrange 2println(SubString("Geeks", 2))  # Finding a part of the parent string# "GeeksforGeeks" with unit range 6println(SubString("GeeksforGeeks", 6))
Output:
Gee
sforGe
eeks
forGeeks

Example 2:
# Julia program to illustrate # the use of String SubString() method   # Finding a part of the parent string# "12345" from starting index 1# to ending index 3println(SubString("12345", 1, 3))   # Finding a part of the parent string# "123456789" from starting index 5# to ending index 8println(SubString("123456789", 5, 8))   # Finding a part of the parent string# "2468" with unitrange 2println(SubString("2468", 2))
Output:
123
5678
468

Julia
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Vectors in Julia
Storing Output on a File in Julia
Formatting of Strings in Julia
Getting rounded value of a number in Julia - round() Method
Creating array with repeated elements in Julia - repeat() Method
Reshaping array dimensions in Julia | Array reshape() Method
Get array dimensions and size of a dimension in Julia - size() Method
Comments in Julia
Taking Input from Users in Julia
while loop in Julia
org.json - JSONArray

A JSONArray is an ordered sequence of values. It provides methods to access values by index and to put values. Following types are supported −
Boolean
Boolean
JSONArray
JSONArray
JSONObject
JSONObject
Number
Number
String
String
JSONObject.NULL object
JSONObject.NULL object
import org.json.JSONArray;
import org.json.JSONObject;

public class JSONDemo {
   public static void main(String[] args) { 
      JSONArray list = new JSONArray();

      list.put("foo");
      list.put(new Integer(100));
      list.put(new Double(1000.21));
      list.put(new Boolean(true));
      list.put(JSONObject.NULL);

      System.out.println("JSONArray: ");
      System.out.println(list);
   }
}
JSONArray: 
["foo",100,1000.21,true,null]


    18 Lectures 
     1.5 hours 

 Dr. Saatya Prasad

    107 Lectures 
     13.5 hours 

 Arnab Chakraborty

    75 Lectures 
     5 hours 

 Revathi Ramachandran

    14 Lectures 
     44 mins

 Zach Miller

    12 Lectures 
     54 mins

 Prof. Paul Cline, Ed.D

    54 Lectures 
     4 hours 

 Gilad James, PhD
 Print
 Add Notes
 Bookmark this page
MySQL Select Rows where two columns do not have the same value?

You can use != operator from MySQL for this. The syntax is as follows:
SELECT *FROM yourTableName
WHERE yourColumnName1 !=yourColumnName2
OR (yourColumnName1 IS NULL AND yourColumnName2IS NOT NULL)
OR (yourColumnName2 IS NULL AND yourColumnName1 IS NOT NULL);
To understand the above syntax, let us create a table. The query to create a table is as follows:
mysql> create table selectTwoColumns
   -> (
   -> Id int NOT NULL AUTO_INCREMENT,
   -> FirstNumber int,
   -> SecondNumber int,
   -> PRIMARY KEY(Id)
   -> );
Query OK, 0 rows affected (0.87 sec)
Insert some records in the table using insert command. The query is as follows:
mysql> insert into selectTwoColumns(FirstNumber,SecondNumber) values(10,20);
Query OK, 1 row affected (0.29 sec)
mysql> insert into selectTwoColumns(FirstNumber,SecondNumber) values(30,40);
Query OK, 1 row affected (0.16 sec)
mysql> insert into selectTwoColumns(FirstNumber,SecondNumber) values(20,20);
Query OK, 1 row affected (0.15 sec)
mysql> insert into selectTwoColumns(FirstNumber,SecondNumber) values(50,60);
Query OK, 1 row affected (0.18 sec)
mysql> insert into selectTwoColumns(FirstNumber,SecondNumber) values(50,50);
Query OK, 1 row affected (0.17 sec)
mysql> insert into selectTwoColumns(FirstNumber,SecondNumber) values(70,NULL);
Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement. The query is as follows:
mysql> select *from selectTwoColumns;
The following is the output:
+----+-------------+--------------+
| Id | FirstNumber | SecondNumber |
+----+-------------+--------------+
|  1 |          10 |           20 |
|  2 |          30 |           40 |
|  3 |          20 |           20 |
|  4 |          50 |           60 |
|  5 |          50 |           50 |
|  6 |          70 |         NULL |
+----+-------------+--------------+
6 rows in set (0.00 sec)
Here is the query to select rows where two columns do not have same value:
mysql> select *from selectTwoColumns
   -> where FirstNumber!=SecondNumber
   -> OR (FirstNumber IS NULL AND SecondNumber IS NOT NULL)
   -> OR (SecondNumber IS NULL AND FirstNumber IS NOT NULL);
The following is the output:
+----+-------------+--------------+
| Id | FirstNumber | SecondNumber |
+----+-------------+--------------+
|  1 |          10 |           20 |
|  2 |          30 |           40 |
|  4 |          50 |           60 |
|  6 |          70 |         NULL |
+----+-------------+--------------+
4 rows in set (0.00 sec)
How to get the value of id attribute in jQuery?

Use jQuery attr() method to get the value of id attribute. You can try to run the following code to learn how to get the value in jQuery −
Live Demo
<html>

   <head>
      <title>jQuery Example</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
   
      <script>
         $(document).ready(function() {
            alert($('#div1').attr('id'));
         });
      </script>
       
   </head>
   
   <body>

      <div id = "div1">
         <p>This is demo text.</p>
      </div>

   </body>
</html>
Overflow Handling in Data Structure

An overflow occurs at the time of the home bucket for a new pair (key, element) is full.
We may tackle overflows by
Search the hash table in some systematic manner for a bucket that is not full.
Linear probing (linear open addressing).
Quadratic probing.
Random probing.
Eliminate overflows by allowing each bucket to keep a list of all pairs for which it is the home bucket.
Array linear list.
Chain.
Open addressing is performed to ensure that all elements are stored directly into the hash table, thus it attempts to resolve collisions implementing various methods.
Linear Probing is performed to resolve collisions by placing the data into the next open slot in the table.
Worst-case find/insert/erase time is θ(m), where m is treated as the number of pairs in the table.
This occurs when all pairs are in the same cluster.
Identifiers are tending to cluster together
Adjacent clusters are tending to coalesce
Increase or enhance the search time
Linear probing searches buckets (H(x)+i2)%b; H(x) indicates Hash function of x
Quadratic probing implements a quadratic function of i as the increment
Examine buckets H(x), (H(x)+i2)%b, (H(x)-i2)%b, for 1<=i<=(b-1)/2
b is indicated as a prime number of the form 4j+3, j is an integer
Random Probing performs incorporating with random numbers.
H(x):= (H’(x) + S[i]) % b
S[i] is a table along with size b-1
S[i] is indicated as a random permutation of integers [1, b-1].
How to deal with error “undefined columns selected when subsetting data frame” in R?

The error “undefined columns selected when subsetting data frame” means that R does not understand the column that you want to use while subsetting the data frame. Generally, this happens when we forget to use comma while subsetting with single square brackets.
Consider the below data frame −
> set.seed(99)
> x1<-rnorm(20,0.5)
> x2<-rpois(20,2)
> x3<-runif(20,2,10)
> x4<-rnorm(20,0.2)
> x5<-rpois(20,5)
> df<-data.frame(x1,x2,x3,x4,x5)
> df
x1 x2 x3 x4 x5
1 0.7139625 4 9.321058 0.33297863 4
2 0.9796581 2 4.298837 -1.47926432 11
3 0.5878287 3 7.389898 -0.07847958 5
4 0.9438585 4 7.873764 -1.35241100 6
5 0.1371621 2 5.534758 -1.17969925 4
6 0.6226740 4 8.786676 -1.15705659 5
7 -0.3638452 1 6.407712 -0.72113718 5
8 0.9896243 2 9.374095 -0.66681774 9
9 0.1358831 2 2.086996 1.85664439 3
10 -0.7942420 0 8.730721 0.04492028 3
11 -0.2457690 3 2.687042 -1.37655243 2
12 1.4215504 3 7.075115 0.82408260 4
13 1.2500544 3 5.373809 0.53022068 5
14 -2.0085540 5 5.287499 -0.19812226 12
15 -2.5409341 1 6.217131 -0.88139693 5
16 0.5002658 3 2.723290 0.12307794 6
17 0.1059810 0 6.288451 -0.32553662 4
18 -1.2450277 2 2.942365 0.59128965 5
19 0.9986315 4 7.012492 -0.48045326 6
20 0.7709538 1 7.801093 -0.54869693 5
Now suppose, you want to select rows where x2 is greater than 2 and you type of the following code −
> df[df$x2>2]
Error in `[.data.frame`(df, df$x2 > 2) : undefined columns selected
It is throwing an error of undefined columns because you forgot the comma after defining your objective. The appropriate way to select the rows where x2 is greater than 2 is as shown below −
> df[df$x2>2,]
x1 x2 x3 x4 x5
1 0.7139625 4 9.321058 0.33297863 4
3 0.5878287 3 7.389898 -0.07847958 5
4 0.9438585 4 7.873764 -1.35241100 6
6 0.6226740 4 8.786676 -1.15705659 5
11 -0.2457690 3 2.687042 -1.37655243 2
12 1.4215504 3 7.075115 0.82408260 4
13 1.2500544 3 5.373809 0.53022068 5
14 -2.0085540 5 5.287499 -0.19812226 12
16 0.5002658 3 2.723290 0.12307794 6
19 0.9986315 4 7.012492 -0.48045326 6
Similarly, to select the rows where x2 is less than 2 is as follows −
> df[df$x2<2,]
x1 x2 x3 x4 x5
7 -0.3638452 1 6.407712 -0.72113718 5
10 -0.7942420 0 8.730721 0.04492028 3
15 -2.5409341 1 6.217131 -0.88139693 5
17 0.1059810 0 6.288451 -0.32553662 4
20 0.7709538 1 7.801093 -0.54869693 5
In the same way, the selection of rows where x2 is greater than 1 is as follows −
> df[df$x2>1,]
x1 x2 x3 x4 x5
1 0.7139625 4 9.321058 0.33297863 4
2 0.9796581 2 4.298837 -1.47926432 11
3 0.5878287 3 7.389898 -0.07847958 5
4 0.9438585 4 7.873764 -1.35241100 6
5 0.1371621 2 5.534758 -1.17969925 4
6 0.6226740 4 8.786676 -1.15705659 5
8 0.9896243 2 9.374095 -0.66681774 9
9 0.1358831 2 2.086996 1.85664439 3
11 -0.2457690 3 2.687042 -1.37655243 2
12 1.4215504 3 7.075115 0.82408260 4
13 1.2500544 3 5.373809 0.53022068 5
14 -2.0085540 5 5.287499 -0.19812226 12
16 0.5002658 3 2.723290 0.12307794 6
18 -1.2450277 2 2.942365 0.59128965 5
19 0.9986315 4 7.012492 -0.48045326 6
How can I show a hidden div when a select option is selected in JavaScript?

To show a hidden div when a select option is selected, you can set the value “style.display” to block.
Following is the code −
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<link rel="stylesheet"
href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<style>
   #hideValuesOnSelect {
      display: none;
   }
</style>
<body>
<select onchange="displayDivDemo('hideValuesOnSelect', this)">
<option value="0">Java</option>
<option value="1">Javascript</option>
</select>
<div id="hideValuesOnSelect">This is the Javascript</div>
</body>
<script>
   function displayDivDemo(id, elementValue) {
      document.getElementById(id).style.display = elementValue.value == 1 ? 'block' : 'none';
   }
</script>
</html>
To run the above program, save the file name anyName.html(index.html) and right click on the
file. Select the option “Open with live server” in VS Code editor.
This will produce the following output −
Whenever you select the second option value (JavaScript), the hidden div will show.
This will produce the following output −
Can I overload static methods in Java?

Overloading is a one of the mechanisms to achieve polymorphism where, a class contains two methods with same name and different parameters.
Whenever you call this method the method body will be bound with the method call based on the parameters.
 Live Demo
public class Calculator {
   public int addition(int a , int b){
      int result = a+b;
      return result;
   }
   public int addition(int a , int b, int c){
      int result = a+b+c;
      return result;
   }
   public static void main(String args[]){
      Calculator cal = new Calculator();
      System.out.println(cal.addition(12, 13, 15));
   }
}
40
Yes, we can overload static methods in Java.
 Live Demo
public class Calculator {
   public static int addition(int a , int b){
      int result = a+b;
      return result;
   }
   public static int addition(int a , int b, int c){
      int result = a+b+c;
      return result;
   }
   public static void main(String args[]){
      System.out.println(Calculator.addition(12, 13));
      System.out.println(Calculator.addition(12, 13, 15));
   }
}
25
40
JavaScript Number - MAX_VALUE

The Number.MAX_VALUE property belongs to the static Number object. It represents constants for the largest possible positive numbers that JavaScript can work with.
The actual value of this constant is 1.7976931348623157 x 10308
The syntax to use MAX_VALUE is −
var val = Number.MAX_VALUE;

Try the following example to learn how to use MAX_VALUE.
<html>
   <head>      
      <script type = "text/javascript">
         <!--
            function showValue() {
               var val = Number.MAX_VALUE;
               document.write ("Value of Number.MAX_VALUE : " + val );
            }
         //-->
      </script>      
   </head>
   
   <body>
      <p>Click the following to see the result:</p>     
      <form>
         <input type = "button" value = "Click Me" onclick = "showValue();" />
      </form>      
   </body>
</html>
Click the following to see the result:

    25 Lectures 
     2.5 hours 

 Anadi Sharma

    74 Lectures 
     10 hours 

 Lets Kode It

    72 Lectures 
     4.5 hours 

 Frahaan Hussain

    70 Lectures 
     4.5 hours 

 Frahaan Hussain

    46 Lectures 
     6 hours 

 Eduonix Learning Solutions

    88 Lectures 
     14 hours 

 Eduonix Learning Solutions
 Print
 Add Notes
 Bookmark this page
How to put a Tkinter window on top of the others?

Whenever we create a GUI program, tkinter generally presents the output screen in the background. In other words, tkinter displays the program window behind other programs. In order to put the tkinter window on top of others, we are required to use attributes('- topmost',True) property. It pulls up the window on the upside.
#Importing the library
from tkinter import *

#Create an instance of tkinter window or frame
win= Tk()

#Setting the geometry of window
win.geometry("600x350")

#Create a Label
Label(win, text= "Hello World! ",font=('Helvetica bold', 15)).pack(pady=20)

#Make the window jump above all
win.attributes('-topmost',True)

win.mainloop()
Running the above code will make the window stay on top all other windows −
numpy.resize

This function returns a new array with the specified size. If the new size is greater than the original, the repeated copies of entries in the original are contained. The function takes the following parameters.
numpy.resize(arr, shape)

Where,
arr
Input array to be resized
shape
New shape of the resulting array
import numpy as np 
a = np.array([[1,2,3],[4,5,6]]) 

print 'First array:' 
print a 
print '\n'

print 'The shape of first array:' 
print a.shape 
print '\n'  
b = np.resize(a, (3,2)) 

print 'Second array:' 
print b 
print '\n'  

print 'The shape of second array:' 
print b.shape 
print '\n'  
# Observe that first row of a is repeated in b since size is bigger 

print 'Resize the second array:' 
b = np.resize(a,(3,3)) 
print b
The above program will produce the following output −
First array:
[[1 2 3]
 [4 5 6]]

The shape of first array:
(2, 3)

Second array:
[[1 2]
 [3 4]
 [5 6]]

The shape of second array:
(3, 2)

Resize the second array:
[[1 2 3]
 [4 5 6]
 [1 2 3]]


    63 Lectures 
     6 hours 

 Abhilash Nelson

    19 Lectures 
     8 hours 

 DATAhill Solutions Srinivas Reddy

    12 Lectures 
     3 hours 

 DATAhill Solutions Srinivas Reddy

    10 Lectures 
     2.5 hours 

 Akbar Khan

    20 Lectures 
     2 hours 

 Pruthviraja L

    63 Lectures 
     6 hours 

 Anmol
 Print
 Add Notes
 Bookmark this page
DFA of a string with at least two 0’s and at least two 1’s - GeeksforGeeks

11 May, 2018
Problem – Draw detereministic finite automata (DFA) of a string with at least two 0’s and at least two 1’s.
The first thing that come to mind after reading this question us that we count the number of 1’s and 0’s. Thereafter if they both are at least 2 the string is accepted else not accepted. But we do not have any concept of memory in a DFA so we cannot do it by this method.
Input  : 1 0 1 1 0 0
Output : Accepted

Input  : 1 1 1 0 1 
Output : Not accepted

Approach Used –The first thing we observe is that both 0’s and 1’s should be at least 2. If any of these is less than 2, then string will not be accepted. In this string will be accepted in only last case where both 0’s and 1’s will be at least 2.
Initially count of both 0 and 1 is zero and we are on state Q0.
Step-1: If input is 1 then count of 1 increases to 1. Goto state Q1If input is 0 then count of 0 increases to 1. Goto state Q3
Step-2: If input is 1 then count of 1 increases to 2. Goto state Q2If input is 0 then count of 0 increases to 1. Goto state Q4
Step-3: If input is 1 then count of 1 keeps increasing by 1. Remain in the same stateIf input is 0 then count of 0 increases to 1. Goto state Q5
Step-4: If input is 1 then count of 1 increases to 1. Goto state Q4If input is 0 then count of 0 increases to 2. Goto state Q6
Step-5: If input is 1 then count of 1 increases to 2. Goto state Q5If input is 0 then count of 0 increases to 2. Goto state Q7
Step-6: If input is 1 then count of 1 keeps increasing by 1. Remain in the same state.If input is 0 then count of 0 increases to 2. Goto state Q8
Step-7: If input is 1 then count of 1 increases to 1. Goto state Q7If input is 0 then count of 0 keeps increasing by 1. Remain in the same state.
Step-8: If input is 1 then count of 1 increases to 2. Goto state Q8If input is 0 then count of 0 keeps increasing by 1. Remain in the same state.
Step-9: If input is 1 then count of 1 keeps increasing by 1. Remain in the same state.If input is 0 then count of 0 keeps increasing by 1. Remain in the same state.If string is finished then ACCEPTED
GATE CS
Theory of Computation & Automata
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Layers of OSI Model
ACID Properties in DBMS
TCP/IP Model
Page Replacement Algorithms in Operating Systems
Types of Operating Systems
Difference between DFA and NFA
Design 101 sequence detector (Mealy machine)
Closure properties of Regular languages
Conversion of Epsilon-NFA to NFA
Boyer-Moore Majority Voting Algorithm
String Interpolation in JavaScript

11 May, 2020
String interpolation is a great programming language feature that allows injecting variables, function calls, arithmetic expressions directly into a string. String interpolation was absent in JavaScript before ES6. String interpolation is a new feature of ES6, that can make multi-line strings without the need for an escape character. We can use apostrophes and quotes easily that they can make our strings and therefore our code easier to read as well. These are some of the reasons to use string interpolation over string concatenation.
Let’s see the difference between string concatenation and string interpolation.
<script>  // String Concatenationfunction myInfo(fname, lname, country) {    return "My name is " + fname + " " + lname + ". "               + country + " is my favorite country."; }console.log(myInfo("john", "doe", "India"));</script>
Output:
My name is john doe. India is my favorite country
In string concatenation, it is hard to maintain string as they grow large it becomes tedious and complex. In order to make it readable, the developer has to maintain all the whitespaces. This is where ES6 comes to rescue with String interpolation. In JavaScript, the template literals (strings wrapped in backticks ` `) and ${expression} as placeholders perform the string interpolation. Now we can write above myInfo function with string interpolation.
<script>  // String Interpolationfunction myInfo(fname, lname, country) {    return `My name is ${fname} ${lname}. ${country} is my favorite country`; }console.log(myInfo("john", "doe", "India"));</script>
Output:
My name is john doe. India is my favorite country
We can see that the code is small and easily readable as compared to concatenation. The template string supports placeholders. The expression like variables, function call, arithmetic can be placed inside the placeholder. These expressions are evaluated at runtime and output is inserted in the string.
<script>  // DEclare and initialize variablesconst x = "GeeksforGeeks";  // I like GeeksforGeeksconsole.log(`I like ${x}.`);  // Function callfunction greet() {    return "hello!";}  // hello! I am a student.console.log(`${greet()} I am a student.`);   // Expression evolution//sum of 5 and 6 is 11. console.log(`sum of 5 and 6 is ${5+6}.`);  </script>
Output:
I like GeeksforGeeks
hello! I am a student.
sum of 5 and 6 is 11.

We can also use conditional statements in expression. For example:
<script>  function isEven(x) {    console.log(`x is ${x%2 === 0 ? 'even' : 'odd'}`);}  isEven(4); // x is even</script>
Output:
x is even
The string interpolation is a great feature. It helps in inserting values into string literals. It makes code more readable and avoids clumsiness.
JavaScript-Misc
Picked
JavaScript
Web Technologies
Web technologies Questions
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python – Join Tuples to Integers in Tuple List

02 Jun, 2020
Sometimes, while working with Python records, we can have a problem in which we need to concatenate all the elements, in order, to convert elements in tuples in List to integer. This kind of problem can have applications in many domains such as day-day and competitive programming. Let’s discuss certain ways in which this task can be performed.
Input : test_list = [(4, 5, 6), (5, 1), (1, 3, 8, 0), (6, 9)]Output : [456, 51, 1380, 69]
Input : test_list = [(4, 5, 6, 8, 9)]Output : [45689]
Method #1 : Using loopThis is brute force method in which this task can be performed. In this, we perform join of all the elements using number creation mathematically compute the result.
# Python3 code to demonstrate working of # Join Tuples to Integers in Tuple List# Using loop  # helpr_fncdef join_tup(tup):    res = tup[0]    for idx in tup[1:]:        res = res * 10 + idx    return res  # initializing listtest_list = [(4, 5), (5, 6), (1, 3), (6, 9)]  # printing original listprint("The original list is : " + str(test_list))  # Join Tuples to Integers in Tuple List# Using loopres = [join_tup(idx) for idx in test_list]  # printing result print("The joined result : " + str(res)) 
The original list is : [(4, 5), (5, 6), (1, 3), (6, 9)]
The joined result : [45, 56, 13, 69]

 
Method #2 : Using map() + join() + int()The combination of above functions can be used to solve the problem. In this, we perform concatenation by string conversion, joining using join() and int() is used to convert result back to integer.
# Python3 code to demonstrate working of # Join Tuples to Integers in Tuple List# Using map() + join() + int()  # initializing listtest_list = [(4, 5), (5, 6), (1, 3), (6, 9)]  # printing original listprint("The original list is : " + str(test_list))  # Join Tuples to Integers in Tuple List# Using map() + join() + int()res = [int(''.join(map(str, idx))) for idx in test_list]  # printing result print("The joined result : " + str(res)) 
The original list is : [(4, 5), (5, 6), (1, 3), (6, 9)]
The joined result : [45, 56, 13, 69]

Python List-of-Tuples
Python list-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Python Classes and Objects
Python OOPs Concepts
Introduction To PYTHON
How to drop one or multiple columns in Pandas Dataframe
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Python | Convert string dictionary to dictionary
Python Program for Fibonacci numbers
Python – Get Nth word in given String

29 Nov, 2019
Sometimes, while working with data, we can have a problem in which we need to get the Nth word of a String. This kind of problem has many application in school and day-day programming. Let’s discuss certain ways in which this problem can be solved.
Method #1 : Using loopThis is one way in which this problem can be solved. In this, we run a loop and check for spaces. The Nth word is when there is N-1th space. We return that word.
# Python3 code to demonstrate working of# Get Nth word in String# using loop  # initializing string test_str = "GFG is for Geeks"  # printing original string print("The original string is : " + test_str)  # initializing N N = 3  # Get Nth word in String# using loopcount = 0res = ""for ele in test_str:    if ele == ' ':        count = count + 1        if count == N:            break        res = ""    else :        res = res + ele  # printing resultprint("The Nth word in String : " + res)
The original string is : GFG is for Geeks
The Nth word in String : for

 
Method #2 : Using split()This is a shorthand with the help of which this problem can be solved. In this, we split the string into a list and then return the Nth occurring element.
# Python3 code to demonstrate working of# Get Nth word in String# using split()  # initializing string test_str = "GFG is for Geeks"  # printing original string print("The original string is : " + test_str)  # initializing N N = 3  # Get Nth word in String# using split()res = test_str.split(' ')[N-1]  # printing resultprint("The Nth word in String : " + res)
The original string is : GFG is for Geeks
The Nth word in String : for

Python string-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Different ways to create Pandas Dataframe
Enumerate() in Python
Read a file line by line in Python
How to Install PIP on Windows ?
Python program to convert a list to string
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Python Program for Fibonacci numbers
GATE | GATE CS 2010 | Question 65

14 Sep, 2021
The grammar S → aSa | bS | c is(A) LL(1) but not LR(1)(B) LR(1)but not LR(1)(C) Both LL(1)and LR(1)(D) Neither LL(1)nor LR(1)Answer: (C)Explanation:
First(aSa) = a
First(bS) = b
First(c) = c
All are mutually disjoint i.e no common terminal 
between them, the given grammar is LL(1).

As the grammar is LL(1) so it will also be LR(1) as LR parsers are
more powerful then LL(1) parsers. and all LL(1) grammar are also LR(1)
So option C is correct. 
Below are more details.
A grammar is LL(1) if it is possible to choose the next production by looking at only the next token in the input string.
Formally, grammar G is LL(1) if and only if 
   For all productions  A → α1 |  α2 | ... | αn, 
      First(αi) ∩ First(αj) =  ∅, 1 ≤ i,j  ≤ n,  i ≠ j.
   For every non-terminal A such that First(A) contains ε, 
      First(A) ∩ Follow(A) = ∅ 
Source: https://s3-ap-southeast-1.amazonaws.com/erbuc/files/4147_870334aa-9922-4f78-9c2c-713e7a7f0d53.pdf
PYQ - Parsing and SDT (Continued) Part 4 with Joyojyoti Acharya | GeeksforGeeks GATE - YouTubeGeeksforGeeks GATE Computer Science17.5K subscribersPYQ - Parsing and SDT (Continued) Part 4 with Joyojyoti Acharya | GeeksforGeeks GATEWatch laterShareCopy linkInfoShoppingTap to unmuteIf playback doesn't begin shortly, try restarting your device.More videosMore videosYou're signed outVideos you watch may be added to the TV's watch history and influence TV recommendations. To avoid this, cancel and sign in to YouTube on your computer.CancelConfirmSwitch cameraShareInclude playlistAn error occurred while retrieving sharing information. Please try again later.Watch on0:000:0011:40 / 58:40•Live•<div class="player-unavailable"><h1 class="message">An error occurred.</h1><div class="submessage"><a href="https://www.youtube.com/watch?v=LdMTs93sekg" target="_blank">Try watching this video on www.youtube.com</a>, or enable JavaScript if it is disabled in your browser.</div></div>Quiz of this Question
GATE-CS-2010
GATE-GATE CS 2010
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GATE | GATE-CS-2014-(Set-2) | Question 65
GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 33
GATE | GATE-CS-2014-(Set-3) | Question 20
GATE | GATE CS 2008 | Question 46
GATE | GATE-CS-2015 (Set 3) | Question 65
GATE | GATE CS 2008 | Question 40
GATE | GATE-CS-2014-(Set-3) | Question 65
GATE | GATE-CS-2014-(Set-1) | Question 51
GATE | GATE CS 1996 | Question 63
GATE | GATE-CS-2004 | Question 31
GATE | GATE CS 2019 | Question 50

22 Jul, 2021
Consider the following four processes with arrival times (in milliseconds) and their length of CPU burst (in milliseconds) as shown below:These processes are run on a single processor using preemptive Shortest Remaining Time First scheduling algorithm. If the average waiting time of the processes is 1 millisecond, then the value of Z is __________.
Note: This was Numerical Type question.(A) 2(B) 3(C) 1(D) 4Answer: (A)Explanation: Using shortest remaining time (SRTF) first CPU scheduling algorithm,
Let Z = 1, then gantt chart will be,
Average waiting time,
= {(4-0-3) + (2-1-1) + (8-3-3) + (5-4-1)} / 4
= (1 + 0 + 2 + 0) / 4
= 3 / 4
= 0.75 
Now, let Z = 2, then gantt chart will be,
Average waiting time,
= {(4-0-3) + (2-1-1) + (9-3-3) + (6-4-2)} / 4
= (1 + 0 + 3 + 0) / 4
= 4 / 4
= 1 
So, answer is 2.
Watch GeeksforGeeks Video explanation :
CPU Scheduling GATE Previous Year Questions Part-II with Viomesh Singh - YouTubeGeeksforGeeks GATE Computer Science17.5K subscribersCPU Scheduling GATE Previous Year Questions Part-II with Viomesh SinghWatch laterShareCopy linkInfoShoppingTap to unmuteIf playback doesn't begin shortly, try restarting your device.You're signed outVideos you watch may be added to the TV's watch history and influence TV recommendations. To avoid this, cancel and sign in to YouTube on your computer.CancelConfirmMore videosMore videosSwitch cameraShareInclude playlistAn error occurred while retrieving sharing information. Please try again later.Watch on0:000:000:00 / 49:57•Live•<div class="player-unavailable"><h1 class="message">An error occurred.</h1><div class="submessage"><a href="https://www.youtube.com/watch?v=maVQoJuMAlM" target="_blank">Try watching this video on www.youtube.com</a>, or enable JavaScript if it is disabled in your browser.</div></div>Quiz of this Question
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GATE | GATE-CS-2014-(Set-2) | Question 65
GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 33
GATE | GATE-CS-2014-(Set-3) | Question 20
GATE | GATE CS 2008 | Question 46
GATE | GATE-CS-2015 (Set 3) | Question 65
GATE | GATE-CS-2014-(Set-1) | Question 51
GATE | GATE-CS-2014-(Set-3) | Question 65
GATE | GATE CS 2008 | Question 40
GATE | GATE CS 1996 | Question 63
GATE | GATE-CS-2015 (Set 2) | Question 55