code-rag-bench/online-tutorials huggingface dataset:
Bootstrap .modal("show") method

The modal(“show”) method opens a modal like below −
The modal is displayed using the modal(“show”) method as shown below −
$("#newModal").modal("show");
Let us see an example of modal(“show”) method −
Live Demo
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style>
    #button1 {
      width: 140px;
      padding: 20px;
      bottom: 150px;
      z-index: 9999;
      font-size: 15px;
      position: absolute;
      margin: 0 auto;
    }
    </style>
 </head>
<body>
  <div class="container">
    <h2>Sample</h2>
    <p>This is demo text.</p>
    <p>This is demo text.</p>
    <p>This is demo text.</p>
    <p>This is demo text.</p>
    <p>This is demo text.</p>
    <p>This is demo text.</p>
    <p>This is demo text.</p>
    <p>This is demo text.</p>
    <p>This is demo text.</p>
    <p>This is demo text.</p>
    <p>This is demo text.</p>
    <button type="button" class="btn btn-default btn-lg" id="button1">Click to hide</button>
      <div class="modal fade" id="newModal" role="dialog">
         <div class="modal-dialog">
           <div class="modal-content">
             <div class="modal-header">
               <button type="button" class="close" data-dismiss="modal">×</button>
               <h4 class="modal-title">Sample Modal</h4>
             </div>
           <div class="modal-body">
             <p>This is demo text.</p>
           </div>
         </div>
      </div>
   </div>
</div>

<script>
  $(document).ready(function(){
    $("#newModal").modal("show");
    $("#button1").click(function(){
      $("#newModal").modal("hide");
    });
  });
</script>

</body>
</html>
How do I list all files of a directory in Python?

os.listdir(my_path) will get you everything that's in the my_path directory - files and directories.
You can use it as follows:
>>> import os
>>> os.listdir('.')
['DLLs', 'Doc', 'etc', 'include', 'Lib', 'libs', 'LICENSE.txt', 'NEWS.txt', 'python.exe', 'pythonw.exe', 'README.txt', 'Scripts', 'share', 'tcl', 'Tools', 'w9xpopen.exe']
If you want just files, you can filter it using isfile:
>>> import os
>>> file_list = [f for f in os.listdir('.') if os.path.isfile(os.path.join('.', f))]
>>> print file_list
['LICENSE.txt', 'NEWS.txt', 'python.exe', 'pythonw.exe', 'README.txt', 'w9xpopen.exe']
Python 3 - List sort() Method

The sort() method sorts objects of list, use compare function if given.
Following is the syntax for sort() method −
list.sort([func])

NA
This method does not return any value; it simply sorts the contents of the given list.
The following example shows the usage of sort() method.
#!/usr/bin/python3

list1 = ['physics', 'Biology', 'chemistry', 'maths']
list1.sort()
print ("list now : ", list1)
When we run above program, it produces the following result −
list now :  ['Biology', 'chemistry', 'maths', 'physics']


    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
C# - nested switch Statements

It is possible to have a switch as part of the statement sequence of an outer switch. Even if the case constants of the inner and outer switch contain common values, no conflicts will arise.
The syntax for a nested switch  statement is as follows −
switch(ch1) {
   case 'A':
   Console.WriteLine("This A is part of outer switch" );
   
   switch(ch2) {
      case 'A':
         Console.WriteLine("This A is part of inner switch" );
         break;
      case 'B': /* inner B case code */
   }
   break;
   case 'B': /* outer B case code */
}

using System;

namespace DecisionMaking {
   class Program {
      static void Main(string[] args) {
         int a = 100;
         int b = 200;
         
         switch (a) {
            case 100: 
            Console.WriteLine("This is part of outer switch ");
            
            switch (b) {
               case 200:
               Console.WriteLine("This is part of inner switch ");
               break;
            }
            break;
         }
         Console.WriteLine("Exact value of a is : {0}", a);
         Console.WriteLine("Exact value of b is : {0}", b);
         Console.ReadLine();
      }
   }
} 
When the above code is compiled and executed, it produces the following result −
This is part of outer switch
This is part of inner switch
Exact value of a is : 100
Exact value of b is : 200


    119 Lectures 
     23.5 hours 

 Raja Biswas

    37 Lectures 
     13 hours 

 Trevoir Williams

    16 Lectures 
     1 hours 

 Peter Jepson

    159 Lectures 
     21.5 hours 

 Ebenezer Ogbu

    193 Lectures 
     17 hours 

 Arnold Higuit

    24 Lectures 
     2.5 hours 

 Eric Frick
 Print
 Add Notes
 Bookmark this page
How to use a not:first-child selector in CSS?

04 Dec, 2018
This selector is used to select every element which is not the first-child of its parent element. It is represented as an argument in the form of :not(first-child) element.
Syntax:
:not( element ) {
  // CSS property
} 

Example:
<!DOCTYPE html><html>    <head>        <title>not first child selector</title>        <style>            h1 {            color:green;            }            div ul:not(:first-child) {                background-color: green;                color:white;                font-style:italic;                font-weight:bold;                width:60%;                margin-left:100px;            }            h1, h2 {                text-align:center;            }        </style>    </head>    <body>        <h1>GeeksforGeeks</h1>        <h2>not:first-child selector </h2>        <div>            <ul style="margin-left:100px">                <li>gfg</li>                <li>geeks</li>                <li>sudo</li>            </ul>            <ul>                <li>Bca</li>                <li>Mca</li>                <li>B.Tech</li>            </ul>        </div>    </body></html>                    
OutputExplanation: The above example shows that a <div> is a container Tag. It contains <ul> Tag so it selects all child elements of <div> tag except its first-child.
Supported Browsers: The browser supported by :not:(first-child) selectors are listed below:
Apple Safari 3.1
Google Chrome 4.0
Firefox 3.0
Opera 9.6
Internet Explorer 7.0
CSS-Misc
Picked
CSS
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Node.js fs.Dirent.isDirectory() Method

19 Jan, 2022
The fs.Dirent.isDirectory() method is an inbuilt application programming interface of class fs.Dirent within File System module which is used to check if the particular dirent describes a Directory or not.
Syntax: 
const dirent.isDirectory()
Parameter: This method does not accept any parameter.Return Value: This method returns true if the particular dirent describes Directory otherwise false.
Below programs illustrates the use of fs.dirent.isDirectory() method in Node.js:
Example 1: Filename: index.js 
Javascript
// Node.js program to demonstrate the// dirent.isDirectory() methodconst fs = require('fs'); // Initiating async functionasync function stop(path) {   // Creating and initiating directory's  // underlying resource handle  const dir = await fs.promises.opendir(path);     // Synchronously reading the directory's  // underlying resource handle using  // readSync() method  for(var i = 0 ; i <= 3 ; i ++ ) {     // Checking if the particular dirent    // is Directory or not by using    // isDirectory() method    const value = (dir.readSync()).isDirectory();     // Display the result    console.log(dir.readSync());    console.log(value);  }} // Catching errorstop('./').catch(console.error);
Run index.js file using the following command: 
node index.js
Output:  
Dirent { name: 'cert.cer', [Symbol(type)]: 1 }
false
Dirent { name: 'certificate1.cer', [Symbol(type)]: 1 }
false
Dirent { name: 'filename.txt', [Symbol(type)]: 1 }
true
Dirent { name: 'GFG.java', [Symbol(type)]: 1 }
false
Example 2: Filename: index.js 
Javascript
// node.js program to demonstrate the// dirent.isDirectory() methodconst fs = require('fs');   // Initiating async functionasync function stop(path) {    let dir = null;     try {   // Creating and initiating directory's  // underlying resource handle  dir = await fs.promises.opendir(        new URL('file:///F:/java/'));   // Using readSync() method  for(var i = 0 ; i <= 3 ; i ++ ) {     // Checking if the particular dirent    // is Directory or not by using    // isDirectory() method    const value = (dir.readSync()).isDirectory();       // Display the result    console.log(dir.readSync());    console.log(value);  }   } finally {      if (dir) {       // Display the result      console.log("dir is closed successfully");       // Synchronously closeSyncing the directory's      // underlying resource handle      const promise = dir.closeSync();    }  }}   // Catching errorstop('./').catch(console.error);
Run index.js file using the following command: 
node index.js
Output:  
Dirent { name: 'cert.cer', [Symbol(type)]: 1 }
false
Dirent { name: 'certificate1.cer', [Symbol(type)]: 1 }
false
Dirent { name: 'features', [Symbol(type)]: 2 }
false
Dirent { name: 'GFG.class', [Symbol(type)]: 1 }
false
dir is closed successfully
Reference: https://nodejs.org/dist/latest-v12.x/docs/api/fs.html#fs_dirent_isdirectory 
kalrap615
sooda367
sweetyty
Node.js-fs-module
Node.js
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Fixed (or static) Partitioning in Operating System in C++

In this tutorial, we are going to learn about the fixed partitioning in the operating system.
Fixed partitioning is one to manage the memory in operating system. It's an old technique. It divides the memory into equal blocks. The size of each block is predefined and can not be changed.
The memory is used for the contiguous processes.
Let's see the sample program that allocates memory based on the process size.
 Live Demo
#include<iostream>
using namespace std;
int main() {
   int blockNumber = 5, processesNumber = 3;
   int blockSize[5] = {4, 4, 4, 4, 4}, processSize[3] = {1, 2, 3};
   int flags[5], allocation[5];
   for(int i = 0; i < 5; i++) {
      flags[i] = 0;
      allocation[i] = -1;
   }
   // allocating the blocks to processes
   for(int i = 0; i < processesNumber; i++) {
      for(int j = 0; j < blockNumber; j++) {
         if(flags[j] == 0 && blockSize[j] >= processSize[i]) {
            allocation[j] = i;
            flags[j] = 1;
            break;
         }
      }
   }
   for (int i = 0; i < blockNumber; i++) {
      if (flags[i] == 1) {
         cout << "Process " << processSize[allocation[i]] << " is allocated" << endl;
      }
   }
   return 0;
}
If you execute the above program, then you will get the following result.
Process 1 is allocated
Process 2 is allocated
Process 3 is allocated
If you have any queries in the tutorial, mention them in the comment section.
How to create dictionary and add key–value pairs dynamically?

28 May, 2020
In this article, we will discuss how we can create a dictionary in JavaScript and add key-value pairs in it. Actually there is no ‘dictionary’ type in JavaScript but we can create key-value pairs by using JavaScript Objects. Create a new JavaScript Object  which will act as dictionary.
Syntax: Key can be a string , integer. If you just write key1 or any number, it will treat as a string.
var dict = { key1 : value1 , 
             key2 : value2 , 
             .... 
           };

Create empty dictionaryvar dict = {};
var dict = {};
Adding Key-Value Pairs in Dictionarydict[new_key] = new_value;orIf new_key is already present in the dictionary then the value of this will be updated to new_value.dict.new_key = new_value;
dict[new_key] = new_value;
orIf new_key is already present in the dictionary then the value of this will be updated to new_value.
dict.new_key = new_value;
Accessing Key-Value Pairsvar value = dict[key];orvar value = dict.key;
var value = dict[key];
or
var value = dict.key;
Iterating the whole dictionaryfor(var key in dict) {
   console.log(key + " : " + dict[key]);
}

for(var key in dict) {
   console.log(key + " : " + dict[key]);
}

Example:
HTML
<!DOCTYPE html><html>    <head>        <title>Dictionary in Javascript</title>    </head>    <body style="text-align: center;">        <h1 style="color: green;">            GeeksforGeeks        </h1>        <p>            var dict = { <br />            "geek" : 1 , <br />            "for" : "2", <br />            "geeks" : 3.5 <br />            }; <br />        </p>            <button onClick="fun()">            Add new Key-Value Pairs        </button>          <p id="demo"></p>            <!-- Script to create dictionary                 and add key-value pairs -->        <script>            function fun() {                var dict = {                    geek: 1,                    for: "2",                    geeks: 3.5,                };                  dict.new_geeks = "new_value";                dict["another_new_geeks"] =                 "another_value";                  var to_show = "var dict = { <br>";                  for (var key in dict) {                    to_show += '"' + key + '" : '                     + dict[key] + "<br>";                }                  to_show += " }; <br>";                  document.getElementById("demo")                .innerHTML = to_show;            }        </script>    </body></html>                    
Output:
JavaScript-Misc
Picked
JavaScript
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
groupadd command in Linux with examples

28 Feb, 2022
Groups in Linux refer to the user groups. In Linux, there can be many users of a single system, (normal user can take uid from 1000 to 60000, and one root user (uid 0) and 999 system users (uid 1 to 999)). In a scenario where there are many users, there might be some privileges that some users have and some don’t, and it becomes difficult to manage all the permissions at the individual user level. So using groups, we can group together a number of users, and set privileges and permissions for the entire group. groupadd command is used to create a new user group. 
Syntax:  
groupadd [option] group_name 
Example:  
sudo groupadd developers 
Note: 
 
Every new group created is registered in the file “/etc/group“. To verify that the group has been created, enter the command  
 
sudo tail /etc/group
Output:  
Output: 
 
The file shows group information in the following format:  
 
group_name : password : group-id : list-of-members
Options: 
 
-f, –force : This option forces the command to silently abort if the group with given already exists. If this option is used with the -g or –gid option and the group id given already exists, the command forcefully ignores the given group id and creates a new and unique group id.  
 
-g, –gid GID : This option is used to provide a group id (numeric) to the new group, and it should be non-negative and unique unless explicitly created to be non-unique (using -o option). If this option is not used, the default id is assigned, which is greater than every other group already present.
-h, –help : Display help message and exit.
-K, –key KEY=VALUE : Overrides /etc/login.defs defaults (GID_MIN, GID_MAX and others). Multiple -K options can be specified. GID_MIN and GID_MAX are the parameters set in /etc/login.defs which defines the minimum and maximum values that a group id can take. Example:  
Example: 
 
 groupadd -K GID_MIN=500 -K GID_MAX=700
 
 
-o, –non-unique : This option permits to add a group with a non-unique GID.
-p, –password PASSWORD : The encrypted password, as returned by crypt(3). The default is to disable the password. This password is visible to the users. You should make sure the password respects the system’s password policy. The group passwords are stored in “/etc/gshadow” file.
-r, –system : Create a system group. The numeric identifiers of new system groups are chosen in the SYS_GID_MIN-SYS_GID_MAX range, defined in login.defs, instead of GID_MIN and GID_MAX.
-R, –root CHROOT_DIR : Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory.
Important Points:  
To add a new user into the group, the group is mentioned using -g option in the command useradd.  
 
sudo useradd -g developers new_user 
To add an existing user to a group, use the usermod command  
 
usermod -g developers existing_user 
 
 
 
KrishnaBirla
linux-command
Linux-system-commands
Picked
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python program to check if the list contains three consecutive common numbers in Python

17 Aug, 2020
Our task is to print the element which occurs 3 consecutive times in a Python list.
Example :
Input : [4, 5, 5, 5, 3, 8]

Output : 5

Input : [1, 1, 1, 64, 23, 64, 22, 22, 22]

Output : 1, 22

Approach :
Create a list.Create a loop for range size – 2.Check if the element is equal to the next element.Again check if the next element is equal to the next element.If both conditions are satisfied then print the element.
Create a list.
Create a loop for range size – 2.
Check if the element is equal to the next element.
Again check if the next element is equal to the next element.
If both conditions are satisfied then print the element.
Example 1 : Only one occurrence of a 3 consecutively occurring element.
# creating the arrayarr = [4, 5, 5, 5, 3, 8]  # size of the listsize = len(arr)  # looping till length - 2for i in range(size - 2):      # checking the conditions    if arr[i] == arr[i + 1] and arr[i + 1] == arr[i + 2]:          # printing the element as the         # conditions are satisfied         print(arr[i])
Output :
5
Example 2 : Multiple occurrences of 3 consecutively occurring elements.
# creating the arrayarr = [1, 1, 1, 64, 23, 64, 22, 22, 22]  # size of the listsize = len(arr)  # looping till length - 2for i in range(size - 2):      # checking the conditions    if arr[i] == arr[i + 1] and arr[i + 1] == arr[i + 2]:          # printing the element as the         # conditions are satisfied         print(arr[i])
Output :
1
22

Python list-programs
python-list
Python
Python Programs
python-list
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
Python String | replace()
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 | Convert string dictionary to dictionary
Python – Read blob object in python using wand library

07 Sep, 2021
BLOB stands for Binary Large OBject. A blob is a data type that can store binary data. This is different than most other data types used in databases, such as integers, floating point numbers, characters, and strings, which store letters and numbers. BLOB is a large complex collection of binary data which is stored in Database. Basically BLOB is used to store media files like images, video and audio files. Due to its ability to store multimedia files it takes a huge disk space. Also length of BLOB may go upto 2, 147, 483, 647 characters. BLOB provides fast multimedia transfer. To get blob file from image :  
     with open('image_path') as f:
    image_blob = f.read()
To read image from blob in Wand :  
with Image(blob=image_binary) as img:
    \\other code
Input Image :  
Code :  
Python3
# import required librariesfrom __future__ import print_function # import Image from wand.image modulefrom wand.image import Image # open image using file handlingwith open('koala.jpeg') as f:     # get blob from image file    image_blob = f.read() # read image using wand from blob filewith Image(blob = image_binary) as img:     # get height of image    print('height =', img.height)     # get width of image    print('width =', img.width)
Output :  
height = 300
width = 400
 
anikaseth98
Python-wand
Python
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 | os.path.join() method
Introduction To PYTHON
Python OOPs Concepts
How to drop one or multiple columns in Pandas Dataframe
How To Convert Python Dictionary To JSON?
Check if element exists in list in Python
Python | Get unique values from a list
Create a directory in Python
HTML DOM querySelector() Method

20 Nov, 2021
The querySelector() method in HTML is used to return the first element that matches a specified CSS selector(s) in the document.
Note: The querySelector() method only returns the first element that matches the specified selectors. To return all the matches, use the querySelectorAll() method.
Syntax:
element.querySelector(selectors);
Selectors are the required field. It Specifies one or more CSS selectors to match the element. These selectors are used to select HTML elements based on their id, classes, types, etc. In the case of multiple selectors, a comma is used to separate each selector. The element which occurs first in the document is the returned element. If the selector matches an id( which should be unique on each page), which is used several times in the document then it will return the first matching element.
Return value :- This method  is used to return the first element that matches a specified CSS selector(s) in the document.
Example: This example describes the use of the DOM querySelector() method to select the very first matching element for the specific selector.
HTML
<!DOCTYPE html><html> <head>    <title>DOM querySelector() Method</title></head> <body style="text-align: center;">    <h1 style="color: green;">GeeksforGeeks</h1>    <h2>querySelector() Method</h2>    <div id="gfg">         <p>This is paragraph 1.</p>          <p>This is paragraph 2.</p>     </div>    <button onclick="myFunction()">Try it</button>    <script>    function myFunction() {        var x = document.getElementById("gfg");        x.querySelector("p").style.backgroundColor = "Green";        x.querySelector("p").style.color = "white";    }    </script></body> </html>
Output:
DOM querySelector() Method
Supported Browsers: The browser supported by querySelector() method are listed below:
Google Chrome 4.0
Internet Explorer 8.0
Microsoft Edge
Firefox 3.5
Opera 10.0
Safari 3.2
simranarora5sos
bhaskargeeksforgeeks
chhabradhanvi
HTML-DOM
Picked
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
List indexOf() Method in Java with Examples - GeeksforGeeks

02 Jan, 2019
This method returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
Syntax:
public int indexOf(Object o)
Parameters: This function has a single parameter, i.e, the element to be searched in the list.
Returns: This method returns the index of first occurrence of the given element in the list and returns “-1” if element is not in the list.
Below programs show the implementation of this method.
Program 1:
// Java code to show the implementation of// indexOf method in list interfaceimport java.util.*;public class GfG {      // Driver code    public static void main(String[] args)    {          // Initializing a list of type Linkedlist        List<Integer> l = new LinkedList<>();        l.add(1);        l.add(3);        l.add(5);        l.add(7);        System.out.println(l);        System.out.println(l.indexOf(5));    }}
[1, 3, 5, 7]
2

Program 2: Below is the code to show implementation of list.hashCode() using Linkedlist.
// Java code to show the implementation of// indexOf method in list interfaceimport java.util.*;public class GfG {      // Driver code    public static void main(String[] args)    {          // Initializing a list of type Linkedlist        List<String> l = new LinkedList<>();        l.add("10");        l.add("15");        l.add("20");        System.out.println(l);        System.out.println(l.indexOf("20"));    }}
[10, 15, 20]
2

Reference:Oracle Docs
Java - util package
Java-Collections
Java-Functions
java-list
Java
Java
Java-Collections
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Object Oriented Programming (OOPs) Concept in Java
HashMap in Java with Examples
How to iterate any Map in Java
Initialize an ArrayList in Java
Interfaces in Java
ArrayList in Java
Multidimensional Arrays in Java
Stack Class in Java
Singleton Class in Java
LinkedList in Java
Definition and Properties of Trees

Tree is a discrete structure that represents hierarchical relationships between individual elements or nodes. A tree in which a parent has no more than two children is called a binary tree.
Definition − A Tree is a connected acyclic undirected graph. There is a unique path between every pair of vertices in G. A tree with N number of vertices contains (N-1) number of edges. The vertex which is of 0 degree is called root of the tree. The vertex which is of 1 degree is called leaf node of the tree and the degree of an internal node is at least 2.
Example − The following is an example of a tree −
The center of a tree is a vertex with minimal eccentricity. The eccentricity of a vertex X in a tree G is the maximum distance between the vertex X and any other vertex of the tree. The maximum eccentricity is the tree diameter. If a tree has only one center, it is called Central Tree and if a tree has only more than one centers, it is called Bi-central Tree. Every tree is either central or bi-central.
Definition − A labeled tree is a tree the vertices of which are assigned unique numbers from 1 to n. We can count such trees for small values of n by hand so as to conjecture a general formula. The number of labeled trees of n number of vertices is nn-2. Two labeled trees are isomorphic if their graphs are isomorphic and the corresponding points of the two trees have the same labels.
Definition − An unlabeled tree is a tree the vertices of which are not assigned any numbers. The number of labeled trees of n number of vertices is (2n)!(n+1)!n! (nth Catalan number)
A rooted tree G is a connected acyclic graph with a special node that is called the root of the tree and every edge directly or indirectly originates from the root. An ordered rooted tree is a rooted tree where the children of each internal vertex are ordered. If every internal vertex of a rooted tree has not more than m children, it is called an m-ary tree. If every internal vertex of a rooted tree has exactly m children, it is called a full m-ary tree. If m = 2, the rooted tree is called a binary tree.
Binary Search tree is a binary tree which satisfies the following property −
X in left sub-tree of vertex V, Value(X) ≤ Value (V)
Y in right sub-tree of vertex V, Value(Y) ≥ Value (V)
So, the value of all the vertices of the left sub-tree of an internal node V are less than or equal to V and the value of all the vertices of the right sub-tree of the internal node V are greater than or equal to V. The number of links from the root node to the deepest node is the height of the Binary Search Tree.
BST_Search(x, k)
if ( x = NIL or k = Value[x] )
   return x;
if ( k < Value[x])
   return BST_Search (left[x], k);
else
   return BST_Search (right[x], k)
Java Program to convert integer to boolean

To convert integer to boolean, firstly let us initialize an integer.
int val = 100;
Now we will declare a variable with primitive boolean. While declaration, we will initialize it with the val value comparing it with an integer using the == operator. If the value matches, the value “True” is returned, else “False” is returned.
boolean bool = (val == 100);
Let us now see the complete example displaying how to convert integer to boolean.
 Live Demo
public class Demo {
   public static void main(String[] args) {
      int val = 100;
      System.out.println("Integer: "+val);
      boolean bool = (val == 100);
      System.out.println("Converted to Bool: "+bool);
   }
}
Integer: 100
Converted to Bool: true
C++ List Library - erase() Function

The C++ function std::list::erase() removes single element from the the list and decreases it's size by one.
Following is the declaration for std::list::erase() function form std::list header.
iterator erase (iterator position);

iterator erase (const_iterator position);

position − Iterator to the list element.
Returns a random access iterator which points to the location from where element was removed.
If position is invalid then behavior is undefined.
Linear i.e. O(n)
The following example shows the usage of std::list::erase() function.
#include <iostream>
#include <list>

using namespace std;

int main(void) {
   list<int> l = {1, 2, 3, 4, 5};

   cout << "Size of list befor erase operation = " << l.size() << endl;

   l.erase(l.begin());

   cout << "Size of list after erase operation = " << l.size() << endl;

   cout << "List contains following elements" << endl;

   for (auto it = l.begin(); it != l.end(); ++it)
      cout << *it << endl;

   return 0;
}
Let us compile and run the above program, this will produce the following result −
Size of list befor erase operation = 5
Size of list after erase operation = 4
List contains following elements
2
3
4
5

 Print
 Add Notes
 Bookmark this page
Tryit Editor v3.7

Tryit: HTML short quotations
How to exclude extra margin between points and the axes for a plot created by using ggplot2 in R?

In a plot created by using ggplot package there exists an extra area around all the sides of the plot which uses extra space, thus we might want to get rid of that space by removing that extra margin area. It can be done by setting the scale for both the axes to zero with the help of scale_x_continuous and scale_y_continuous function.
Consider the below data frame −
 Live Demo
set.seed(151)
x<-rnorm(20,5,1)
y<-rnorm(20,5,2)
df<-data.frame(x,y)
df
      x         y
1  4.948461 2.255857
2  5.765737 1.726474
3  4.853260 4.280697
4  4.886814 7.402230
5  4.604489 3.708252
6  5.782276 3.978782
7  3.602522 3.801754
8  3.981162 6.091206
9  5.229476 4.017412
10 5.672173 5.383071
11 4.515448 3.882945
12 5.560609 6.845399
13 5.066156 7.307996
14 3.650124 2.255179
15 4.757084 7.580363
16 3.763259 7.309804
17 3.525322 7.891359
18 7.437159 5.522026
19 5.673526 8.858292
20 5.310040 3.800228
Loading ggplot2 package and creating scatterplot between x and y −
library(ggplot2)
ggplot(df,aes(x,y))+geom_point()
Creating scatterplot between x and y by excluding the extra margin area −
ggplot(df,aes(x,y))+geom_point()+scale_x_continuous(expand=c(0,0))+scale_y_continuous(expand=c(0,0))
Python | Pandas DatetimeIndex.to_series() - GeeksforGeeks

29 Dec, 2018
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Pandas DatetimeIndex.to_series() function create a Series with both index and values equal to the index keys useful with map for returning an indexer based on an index.
Syntax: DatetimeIndex.to_series(keep_tz=False, index=None, name=None)
Parameters :keep_tz : return the data keeping the timezoneindex : index of resulting Series. If None, defaults to original indexname : name of resulting Series. If None, defaults to name of original index
Return : Series
Example #1: Use DatetimeIndex.to_series() function to create a series object from the given DatetimeIndex object. Also set the value of index for the series.
# importing pandas as pdimport pandas as pd  # Create the DatetimeIndex# Here 'S' represents secondly frequency didx = pd.DatetimeIndex(start ='2018-11-15 09:45:10', freq ='S', periods = 5)  # Print the DatetimeIndexprint(didx)
Output :
Now we want to construct a series out of the DatetimeIndex object.
# construct the seriesdidx.to_series(index =['A', 'B', 'C', 'D', 'E'])
Output :As we can see in the output, the function has returned a series object constructed from the didx DatetimeIndex object. Example #2: Use DatetimeIndex.to_series() function to create a series object from the given DatetimeIndex object. Also set the value of index for the series.
# importing pandas as pdimport pandas as pd  # Create the DatetimeIndex# Here 'M' represents monthly frequency didx = pd.DatetimeIndex(start ='2015-03-02', freq ='M', periods = 5)  # Print the DatetimeIndexprint(didx)
Output :
Now we want to construct a series out of the DatetimeIndex object.
# construct the seriesdidx.to_series(index =['First', 'Second', 'Third', 'Fourth', 'Fifth'])
Output :As we can see in the output, the function has returned a series object constructed from the didx DatetimeIndex object.
Python pandas-datetimeIndex
Python-pandas
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Enumerate() in Python
How to Install PIP on Windows ?
Iterate over a list in Python
Different ways to create Pandas Dataframe
Python String | replace()
Create a Pandas DataFrame from Lists
Reading and Writing to text files in Python
sum() function in Python
*args and **kwargs in Python
Python | sympy.collect() method - GeeksforGeeks

18 Jun, 2019
With the help of sympy.collect() method, we are able to collect the mathematical expressions having same power.
Syntax : sympy.collect()Return : Return mathematical expression having same powers.
Example #1 :In this example, we can see that by using sympy.collect() method, all the same powers of variables are collected together as a same mathematical expression.
# import sympyfrom sympy import * x, y, z = symbols('x y z')gfg_exp = x * y + x - 3 + 2 * x**2 - z * x**2 + x**3  # Using sympy.collect() methodgfg_exp = collect(gfg_exp, x)  print(gfg_exp)
Output :
x**3 + x**2*(2 – z) + x*(y + 1) – 3
Example #2 :
# import sympyfrom sympy import * x, y, z = symbols('x y z')gfg_exp = x * x + x - 3 + 2 * z**2 - y * x**2 + x**3  # Using sympy.collect() methodgfg_exp = collect(gfg_exp, x)  print(gfg_exp)
Output :
x**3 + x**2*(1 – y) + x + 2*z**2 – 3
SymPy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Enumerate() in Python
How to Install PIP on Windows ?
Different ways to create Pandas Dataframe
Python String | replace()
Create a Pandas DataFrame from Lists
*args and **kwargs in Python
How To Convert Python Dictionary To JSON?
sum() function in Python
How to drop one or multiple columns in Pandas Dataframe
Maximum of Absolute Value Expression in C++

Suppose we have two arrays of integers with equal lengths, we have to find the maximum value of: |arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|. Where the maximum value is taken over all 0 <= i, j < arr1.length. So if the given two arrays are [1,2,3,4] and [-1,4,5,6], the output will be 13.
To solve this, we will follow these steps −
Define a method called getVal, that will take array v
Define a method called getVal, that will take array v
maxVal := -inf, minVal := inf
maxVal := -inf, minVal := inf
for i in range 0 to size of vminVal := min of v[i] and minValmaxVal := max of v[i] and maxVal
for i in range 0 to size of v
minVal := min of v[i] and minVal
minVal := min of v[i] and minVal
maxVal := max of v[i] and maxVal
maxVal := max of v[i] and maxVal
return maxVal – minVal
return maxVal – minVal
From the main method, do the following
From the main method, do the following
make an array ret of size 4
make an array ret of size 4
n := size of arr1
n := size of arr1
for i in range 0 to n – 1insert arr1[i] – arr2[i] + i into ret[0]insert arr1[i] + arr2[i] + i into ret[1]insert arr1[i] – arr2[i] - i into ret[2]insert arr1[i] + arr2[i] - i into ret[3]
for i in range 0 to n – 1
insert arr1[i] – arr2[i] + i into ret[0]
insert arr1[i] – arr2[i] + i into ret[0]
insert arr1[i] + arr2[i] + i into ret[1]
insert arr1[i] + arr2[i] + i into ret[1]
insert arr1[i] – arr2[i] - i into ret[2]
insert arr1[i] – arr2[i] - i into ret[2]
insert arr1[i] + arr2[i] - i into ret[3]
insert arr1[i] + arr2[i] - i into ret[3]
ans := -inf
ans := -inf
for i in range 0 to 3ans := max of ans and getVal(ret[i])
for i in range 0 to 3
ans := max of ans and getVal(ret[i])
ans := max of ans and getVal(ret[i])
return ans
return ans
Let us see the following implementation to get better understanding −
 Live Demo
#include <bits/stdc++.h>
using namespace std;
class Solution {
   public:
   int getVal(vector <int>& v){
      int maxVal = INT_MIN;
      int minVal = INT_MAX;
      for(int i = 0; i < v.size(); i++){
         minVal = min(v[i], minVal);
         maxVal = max(v[i], maxVal);
      }
      return maxVal - minVal;
   }
   int maxAbsValExpr(vector<int>& arr1, vector<int>& arr2) {
      vector <int> ret[4];
      int n = arr1.size();
      for(int i = 0; i < n; i++){
         ret[0].push_back(arr1[i] - arr2[i] + i);
         ret[1].push_back(arr1[i] + arr2[i] + i);
         ret[2].push_back(arr1[i] - arr2[i] - i);
         ret[3].push_back(arr1[i] + arr2[i] - i);
      }
      int ans = INT_MIN;
      for(int i = 0; i < 4; i++){
         ans = max(ans, getVal(ret[i]));
      }
      return ans;
   }
};
main(){
   vector<int> v1 = {1,2,3,4}, v2 = {-1, 4, 5, 6};
   Solution ob;
   cout << (ob.maxAbsValExpr(v1, v2));
}
[1,2,3,4]
[-1,4,5,6]
13
Program to find out the number of special numbers in a given range in Python

Suppose we are given a range of integer numbers and are asked to find out the special numbers in the range. A special number is a number that is a positive integer having only 1 digit in its decimal representation. A number that has more than 1 digit in its decimal representation can also be special if the number is divisible by the count of digits in its decimal representation and the quotient value is itself a special number. We return the count of special numbers in the given range (left_limit, right_limit).
So, if the input is like left_limit = 5, right_limit = 30, then the output will be 13.
The special numbers in this range are: 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 24, and 28.
To solve this, we will follow these steps −
if right_limit < 10, thenreturn right_limit - left_limit + 1
return right_limit - left_limit + 1
len_right := size of string representation of (right_limit)
number_list := [0,1,2,3,4,5,6,7,8,9,10,12,14,16,18]
for j in range 2 to len_right + 1, dofor each k in number_list, dotemp1 := k * jif size of string representation of temp1 is same as j, theninsert temp1 at the end of number_listotherwise when len(str(temp1)) > j, thencome out from the loopif number_list[size of number_list - 1] >= right_limit, thencome out from the loop
for each k in number_list, dotemp1 := k * jif size of string representation of temp1 is same as j, theninsert temp1 at the end of number_listotherwise when len(str(temp1)) > j, thencome out from the loopif number_list[size of number_list - 1] >= right_limit, thencome out from the loop
temp1 := k * j
if size of string representation of temp1 is same as j, theninsert temp1 at the end of number_list
insert temp1 at the end of number_list
otherwise when len(str(temp1)) > j, thencome out from the loop
come out from the loop
if number_list[size of number_list - 1] >= right_limit, thencome out from the loop
come out from the loop
delete duplicate values from number_list and sort
count := 0
for each temp2 in number_list, doif temp2 >= left_limit and temp2 <= right_limit, thencount := count + 1
if temp2 >= left_limit and temp2 <= right_limit, thencount := count + 1
count := count + 1
return count
Let us see the following implementation to get better understanding −
def strange(left_limit, right_limit):
   if right_limit < 10:
      return right_limit - left_limit + 1
len_right = len(str(right_limit))
number_list = [0,1,2,3,4,5,6,7,8,9,10,12,14,16,18]
for j in range(2, len_right + 1):
for k in number_list:
temp1 = k*j
if len(str(temp1)) == j:
number_list.append(temp1)
elif len(str(temp1)) > j:
break
if number_list[len(number_list)-1] >= right_limit:
break
number_list = list(set(number_list))
count = 0
for temp2 in number_list:
if temp2 >= left_limit and temp2 <= right_limit:
count = count + 1
return count
print(strange(5, 30))
5, 30
13
HTML | <img> align Attribute

17 Feb, 2022
The <img> align attribute is used to set the alignment of an image. It is an inline element. It is used to specify the alignment of the image according to surrounding elements. It is not supported by HTML 5. HTML 5 uses CSS property instead of this attribute.
Syntax: 
<img align="left|right|middle|top|bottom">
Attribute Values: 
left: It sets the alignment of the image to the left.
right: It sets the alignment of the image to the right.
middle: It sets the alignment of the image to the middle.
top: It sets the alignment of the image to the top.
bottom: It sets the alignment of the image to the bottom.
Example: 
html
<!DOCTYPE html><html> <head>    <title>        HTML img align Attribute    </title></head> <body>    <h1>GeeksforGeeks</h1>     <h2>HTML img align Attribute</h2>     <img src="https://media.geeksforgeeks.org/wp-content/uploads/20190506164011/logo3.png"        alt="GeeksforGeeks logo"        align="right">    <img src="https://media.geeksforgeeks.org/wp-content/uploads/20190506164011/logo3.png"        alt="GeeksforGeeks logo"        align="left"></body> </html>
Output:  
Supported Browsers: The browser supported by HTML <img> align Attribute are listed below: 
Google Chrome
Internet Explorer
Firefox
Safari
Opera 
HTML is the foundation of web pages, is used for webpage development by structuring websites and web apps. You can learn HTML from the ground up by following this HTML Tutorial and HTML Examples.
chhabradhanvi
HTML-Attributes
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Types of CSS (Cascading Style Sheet)
DOM (Document Object Model)
How to make elements float to center?
How to Insert Form Data into Database using PHP ?
How to Show Images on Click using HTML ?
Installation of Node.js on Linux
Difference between var, let and const keywords in JavaScript
How to fetch data from an API in ReactJS ?
Differences between Functional Components and Class Components in React
Remove elements from a JavaScript Array
Exporting a Pandas DataFrame to an Excel file

02 Sep, 2020
Let us see how to export a Pandas DataFrame to an Excel file. 
Algorithm:
Create the DataFrame.Determine the name of the Excel file.Call to_excel() function with the file name to export the DataFrame.
Create the DataFrame.
Determine the name of the Excel file.
Call to_excel() function with the file name to export the DataFrame.
Example 1:
Python3
# importing the moduleimport pandas as pd  # creating the DataFramemarks_data = pd.DataFrame({'ID': {0: 23, 1: 43, 2: 12,                                 3: 13, 4: 67, 5: 89,                                 6: 90, 7: 56, 8: 34},                          'Name': {0: 'Ram', 1: 'Deep',                                   2: 'Yash', 3: 'Aman',                                   4: 'Arjun', 5: 'Aditya',                                   6: 'Divya', 7: 'Chalsea',                                   8: 'Akash' },                          'Marks': {0: 89, 1: 97, 2: 45, 3: 78,                                    4: 56, 5: 76, 6: 100, 7: 87,                                    8: 81},                          'Grade': {0: 'B', 1: 'A', 2: 'F', 3: 'C',                                    4: 'E', 5: 'C', 6: 'A', 7: 'B',                                    8: 'B'}})  # determining the name of the filefile_name = 'MarksData.xlsx'  # saving the excelmarks_data.to_excel(file_name)print('DataFrame is written to Excel File successfully.')
Output:
DataFrame is written to Excel File successfully.
The Excel file is:
Example 2: We can also first use the ExcelWriter() method to save it.
Python3
# importing the moduleimport pandas as pd  # creating the DataFramecars_data = pd.DataFrame({'Cars': ['BMW', 'Audi', 'Bugatti',                                    'Porsche', 'Volkswagen'],                          'MaxSpeed': [220, 230, 240, 210, 190],                          'Color': ['Black', 'Red', 'Blue',                                     'Violet', 'White']})  # writing to Exceldatatoexcel = pd.ExcelWriter('CarsData1.xlsx')  # write DataFrame to excelcars_data.to_excel(datatoexcel)  # save the exceldatatoexcel.save()print('DataFrame is written to Excel File successfully.')
Output:
DataFrame is written to Excel File successfully.
Python pandas-dataFrame
Python-pandas
Python
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
Python | os.path.join() method
Check if element exists in list in Python
How To Convert Python Dictionary To JSON?
Python | Get unique values from a list
Python | datetime.timedelta() function
How to see cache statistics in Linux?

31 Jan, 2019
Cache is a very important part of the computer hardware to give superfast response time.
Cache PerformanceWhen the processor needs to read or write a location in main memory, it first checks for a corresponding entry in the cache.
If the processor finds that the memory location is in the cache, a cache hit has occurred and data is read from cacheIf the processor does not find the memory location in the cache, a cache miss has occurred. For a cache miss, the cache allocates a new entry and copies in data from main memory, then the request is fulfilled from the contents of the cache.
The performance of cache memory is frequently measured in terms of a quantity called Hit ratio.
Hit ratio = hit / (hit + miss) =  no. of hits/total accesses
To monitor the performance of your cache, linux provides some excellent library: Cachestat.
Cachestat is not directly available, it is deprecated by linux.Cachestat uses the perf tools, which is a part of linux-tools library.
To install perf-tools, open terminal and run:
sudo apt-get install linux-tools-common linux-tools-generic
Then, to install cachestat, run:
wget https://raw.githubusercontent.com/brendangregg/perf-tools/master/fs/cachestat
To make it executable, run:
chmod +x cachestat
Finally run it:
sudo ./cachestat
If you get a lot of misses, you should probably run diagnostics.
This article is contributed by Suprotik Dey. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
linux-command
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.