code-rag-bench/online-tutorials huggingface dataset:
Increment (Decrement) operators require L-value Expression

28 May, 2017
What will be the output of the following program?
#include<stdio.h>int main(){   int i = 10;   printf("%d", ++(-i));   return 0;}
A) 11 B) 10 C) -9 D) None
Answer: D, None – Compilation Error.
Explanation:
In C/C++ the pre-increment (decrement) and the post-increment (decrement) operators require an L-value expression as operand. Providing an R-value or a const qualified variable results in compilation error.
In the above program, the expression -i results in R-value which is operand of pre-increment operator. The pre-increment operator requires an L-value as operand, hence the compiler throws an error.
The increment/decrement operators needs to update the operand after the sequence point, so they need an L-value. The unary operators such as -, +, won’t need L-value as operand. The expression -(++i) is valid.
In C++ the rules are little complicated because of references. We can apply these pre/post increment (decrement) operators on references variables that are not qualified by const. References can also be returned from functions.
Puzzle phrased by Venki. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
C-Operators
C Language
C++
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python – Itertools.count()

01 Mar, 2020
Python Itertools are a great way of creating complex iterators which helps in getting faster execution time and writing memory-efficient code. Itertools provide us with functions for creating infinite sequences and itertools.count() is one such function and it does exactly what it sounds like, it counts!
Note: For more information, refer to Python Itertools
itertools.count() are generally used with map() to generate consecutive data points which is useful in when working with data. It can also be used with zip to add sequences by passing count as parameter.
Syntax: itertools.count(start=0, step=1)
Parameters:start: Start of the sequence (defaults to 0)step: Difference between consecutive numbers (defaults to 1)
Returns: Returns a count object whose .__next__() method returns consecutive values.
Let us get a deep understanding of this mighty sword using some simple Python programs.
Example #1: Creating evenly spaced list of numbersitertools.count() can be used to generate infinite recursive sequences easily. Lets have a look
# Program for creating a list of# even and odd list of integers# using count()    from itertools import count  # creates a count iterator objectiterator =(count(start = 0, step = 2))  # prints a odd list of integersprint("Even list:",       list(next(iterator) for _ in range(5)))  # creates a count iterator objectiterator = (count(start = 1, step = 2))  # prints a odd list of integersprint("Odd list:",       list(next(iterator) for _ in range(5)))
Output :
Even list: [0, 2, 4, 6, 8]
Odd list: [1, 3, 5, 7, 9]

In the same way, we can also generate a sequence of negative and floating-point numbers. For better accuracy of floating-point numbers use (start + step * i for i in count()).
Example #2: Emulating enumerate() using itertools.count()As mentioned earlier, count() can be used with zip(). Let’s see how can we use it to mimic the functionality of enumerate() without even knowing the length of list beforehand!
# Program to emulate enumerate() # using count()  # list containing some stringsmy_list =["Geeks", "for", "Geeks"]  # count spits out integers for # each value in my listfor i in zip(count(start = 1,                    step = 1), my_list):          # prints tuple in an enumerated     # format    print(i)
Output :
(1, 'Geeks')
(2, 'for')
(3, 'Geeks')

Note: Extra care must be taken while using itertools.count() as it is easy to get stuck in an infinite loop.
The following code functions the same as while True: thus proper termination condition must be specified.
for i in count(start=0, step=2): 
    print(i)

Python-itertools
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Different ways to create Pandas Dataframe
Read a file line by line in Python
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Python Classes and Objects
Iterate over a list in Python
Python OOPs Concepts
Convert integer to string in Python
numpy.empty_like() in Python

29 Nov, 2018
numpy.empty_like(a, dtype = None, order = ‘K’, subok = True) : Return a new array with the same shape and type as a given array.Parameters :
shape : Number of rows
order : C_contiguous or F_contiguous
dtype : [optional, float(by Default)] Data type of returned array.  
subok : [bool, optional] to make subclass of a or not

Return :
array with the same shape and type as a given array.
# Python Program illustrating# numpy.empty_like method  import numpy as geek  a = geek.empty_like([2, 2], dtype = int)print("\nMatrix a : \n", a)  c = a = ([1,2,3], [4,5,6])print("\nMatrix c : \n", geek.empty_like(c))
Output :
Matrix a : 
 [  16843008 1058682594]

Matrix c : 
 [[0 0 0]
 [0 0 0]]

Note :These codes won’t run on online-ID. Please run them on your systems to explore the working.
This article is contributed by Mohit Gupta_OMG . 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.
Python numpy-arrayCreation
Python-numpy
Python
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()
How to Install PIP on Windows ?
*args and **kwargs in Python
Python Classes and Objects
Iterate over a list in Python
Python OOPs Concepts
Python | Scipy integrate.simps() method

23 Jan, 2020
With the help of scipy.integrate.simps() method, we can get the integration of y(x) using samples along the axis and composite simpson’s rule by using scipy.integrate.simps() method.
Syntax : scipy.integrate.simps(y, x)Return : Return the integrated value of y(x) using samples.
Example #1 :In this example we can see that by using scipy.integrate.simps() method, we are able to get the integrated value of y(x) using samples and composite simpson’s rule by using this method.
# import numpy and scipy.integrateimport numpy as npfrom scipy import integrate  x = np.arange(0, 10)y = np.arange(0, 10)# using scipy.integrate.simps() methodgfg = integrate.simps(y, x)  print(gfg)
Output :
40.5
Example #2 :
# import numpy and scipy.integrateimport numpy as npfrom scipy import integrate  x = np.arange(0, 10)y = np.sqrt(x)# using scipy.integrate.simps() methodgfg = integrate.simps(y, x)  print(gfg)
Output :
17.875036119764566
Python-scipy
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
HTML <input> size Attribute

The size attribute of the <input> element is used to set the width of the input. The more the width would lead to a textbox with more width. You can set the size attribute for the following input types − text, search, email, password, tel and url.
Following is the syntax −
<input size="size_num">
Above, size_num is the width of the input you need to set in numbers. The default is 20.
Let us now see an example to implement the size attribute of the <input> element −
 Live Demo
<!DOCTYPE html>
<html>
<body>
<h2>Register</h2>
<form action="" method="get">
   Id − <input type="text" name="id" placeholder="Enter UserId here..." size = "25" required><br>
   Password − <input type="password" name="pwd" placeholder="Enter password here..." required><br>
   DOB − <input type="date" name="dob" placeholder="Enter date of birth here..."><br>
   Telephone − <input type="tel" name="tel" placeholder="Enter mobile number here..." required><br>
   Email − <input type="email" name="email" placeholder="Enter email here..." size = "35"><br><br>
   <button type="submit" value="Submit">Submit</button>
</form>
</body>
</html>
In the above example, we have some fields with a button −
<form action="" method="get">
   Id − <input type="text" name="id" placeholder="Enter UserId here..." size = "25" required><br>
   Password − <input type="password" name="pwd" placeholder="Enter password here..." required><br>
   DOB − <input type="date" name="dob" placeholder="Enter date of birth here..."><br>
   Telephone − <input type="tel" name="tel" placeholder="Enter mobile number here..." required><br>
   Email − <input type="email" name="email" placeholder="Enter email here..." size = "35"><br><br>
   <button type="submit" value="Submit">Submit</button>
</form>
Now, let’s say we want a bigger textbox i.e. with bigger width. For that, we used the size attribute to set the width in numbers −
<input type="text" name="id" placeholder="Enter UserId here..." size = "25" required>
Python | How to sort a list of strings

23 May, 2022
Given a list of strings, the task is to sort that list based on given requirement. There are multiple scenarios possible while sorting a list of string, like –
Sorting in alphabetical/reverse order.
Based on length of string character
Sorting the integer values in list of string etc.
Let’s discuss various ways to perform this task. 
Example #1: Using sort() function. 
Python3
# Python program to sort a list of strings lst = ['gfg', 'is', 'a', 'portal', 'for', 'geeks'] # Using sort() functionlst.sort() print(lst)
['a', 'for', 'geeks', 'gfg', 'is', 'portal']
  Example #2: Using sorted() function. 
Python3
# Python program to sort a list of strings lst = ['gfg', 'is', 'a', 'portal', 'for', 'geeks'] # Using sorted() functionfor ele in sorted(lst):    print(ele)
a
for
geeks
gfg
is
portal
  Example #3: Sort by length of strings 
Python3
# Python program to sort a list of strings lst = ['Geeksforgeeks', 'is', 'a', 'portal', 'for', 'geeks'] # Using sort() function with key as lenlst.sort(key = len) print(lst)
['a', 'is', 'for', 'geeks', 'portal', 'Geeksforgeeks']
  Example #4: Sort string by integer value 
Python3
# Python program to sort a list of strings lst = ['23', '33', '11', '7', '55'] # Using sort() function with key as intlst.sort(key = int) print(lst)
['7', '11', '23', '33', '55']
Example #5: Sort in descending order 
Python3
# Python program to sort a list of strings lst = ['gfg', 'is', 'a', 'portal', 'for', 'geeks'] # Using sort() functionlst.sort(reverse = True) print(lst)
['portal', 'is', 'gfg', 'geeks', 'for', 'a']
AshokJaiswal
Python list-programs
python-list
python-string
Python
Python Programs
python-list
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Different ways to create Pandas Dataframe
Enumerate() in Python
Read a file line by line in Python
Python String | replace()
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 | Convert string dictionary to dictionary
Python | Merge list elements

28 Jan, 2019
Sometimes, we require to merge some of the elements as single element in the list. This is usually with the cases with character to string conversion. This type of task is usually required in the development domain to merge the names into one element. Let’s discuss certain ways in which this can be performed.
Method #1 : Using join() + List SlicingThe join function can be coupled with list slicing which can perform the task of joining each character in a range picked by the list slicing functionality.
# Python3 code to demonstrate # merging list elements# using join() + list slicing  # initializing list  test_list = ['I', 'L', 'O', 'V', 'E', 'G', 'F', 'G']  # printing original listprint ("The original list is : " + str(test_list))  # using join() + list slicing# merging list elementstest_list[5 : 8] = [''.join(test_list[5 : 8])]  # printing result print ("The list after merging elements : " +  str(test_list))
The original list is : ['I', 'L', 'O', 'V', 'E', 'G', 'F', 'G']
The list after merging elements : ['I', 'L', 'O', 'V', 'E', 'GFG']

Method #2 : Using reduce() + lambda + list slicingThe task of joining each element in a range is performed by reduce function and lambda. reduce function performs the task for each element in the range which is defined by the lambda function. It works with Python2 only
# Python code to demonstrate # merging list elements# using reduce() + lambda + list slicing  # initializing list  test_list = ['I', 'L', 'O', 'V', 'E', 'G', 'F', 'G']  # printing original listprint ("The original list is : " + str(test_list))  # using reduce() + lambda + list slicing# merging list elementstest_list[5 : 8] = [reduce(lambda i, j: i + j, test_list[5 : 8])]  # printing result print ("The list after merging elements : " +  str(test_list))
The original list is : ['I', 'L', 'O', 'V', 'E', 'G', 'F', 'G']
The list after merging elements : ['I', 'L', 'O', 'V', 'E', 'GFG']

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
Python String | replace()
How to Install PIP on Windows ?
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
HTML - <menu> Tag

The HTML <menu> tag is used for creating a menu list. This tag has been deprecated in HTML and redefined in HTML5.
<!DOCTYPE html>
<html>

   <head>
      <title>HTML menu Tag</title>
   </head>

   <body>
      <menu>
         <li>ol - ordered list</li>
         <li>ul - unordered list</li>
         <li>dir - directory list</li>
         <li>menu - menu list</li>
      </menu>
   </body>

</html>
This will produce the following result −
ol - ordered list
ul - unordered list
dir - directory list
menu - menu list
This tag supports all the global attributes described in − HTML Attribute Reference
The HTML <menu> tag also supports the following  additional attributes −
This tag supports all the event attributes described in − HTML Events Reference

    19 Lectures 
     2 hours 

 Anadi Sharma

    16 Lectures 
     1.5 hours 

 Anadi Sharma

    18 Lectures 
     1.5 hours 

 Frahaan Hussain

    57 Lectures 
     5.5 hours 

 DigiFisk (Programming Is Fun)

    54 Lectures 
     6 hours 

 DigiFisk (Programming Is Fun)

    45 Lectures 
     5.5 hours 

 DigiFisk (Programming Is Fun)
 Print
 Add Notes
 Bookmark this page
How to draw a filled polygon in OpenCV using Java?

The org.opencv.imgproc package of Java OpenCV library contains a class named Imgproc. To draw a filled polygon you need to invoke the fillPoly() method of this class. This method accepts the following parameters −
A Mat object representing the image on which the polygon is to be drawn.
A Mat object representing the image on which the polygon is to be drawn.
A-List object holding the objects of the type MatOfPoint.
A-List object holding the objects of the type MatOfPoint.
A Scalar object representing the color of the polygon.
A Scalar object representing the color of the polygon.
An integer representing the line type.
An integer representing the line type.
import java.util.ArrayList;
import java.util.List;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class DrawingFilledPolygon {
   public static void main(String args[]) {
      //Loading the OpenCV core library
      System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
      //Loading the OpenCV core library
      System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
      //Reading the source image in to a Mat object
      Mat src = Imgcodecs.imread("D:\\images\\blank.jpg");
      //Drawing a polygon
      List<MatOfPoint>list = new ArrayList<MatOfPoint>();
         list.add(new MatOfPoint (
         new Point(208, 71), new Point(421, 161),
         new Point(332, 52), new Point(369, 250),
         new Point(421, 161), new Point(226, 232),
         new Point(369, 250), new Point(208, 71),
         new Point(226, 232), new Point(332, 52)));
      Scalar color = new Scalar(64, 64, 64);
      int lineType = Imgproc.LINE_8;
      Imgproc.fillPoly(src, list, color, lineType);
      //Saving and displaying the image
      Imgcodecs.imwrite("arrowed_line.jpg", src);
      HighGui.imshow("Drawing a polygon", src);
      HighGui.waitKey();
   }
}
On executing, the above program generates the following window −
Checking triangular inequality on list of lists in Python

The sum of two sides of a triangle is always greater than the third side. This is called triangle inequality. Python list of lists we will identify those sublists where the triangle inequality holds good.
We will first get all the sublists sorted. Then for each sublist we will check if the if the sum of first two elements is greater than the third element.
 Live Demo
Alist = [[3, 8, 3], [9, 8, 6]]
# Sorting sublist of list of list
for x in Alist:
   x.sort()
# Check for triangular inequality
for e in Alist:
   if e[0] + e[1] > e[2]:
      print("The sublist showing triangular inequality:",x)
Running the above code gives us the following result −
The sublist showing triangular inequality:
[6, 8, 9]
In this method, we also first sort the sublists and then use list comprehension to go through each of the sublists to check which one satisfies the triangle inequality.
Alist = [[3, 8, 3], [9, 8, 6]]
# Sorting sublist of list of list
for x in Alist:
   x.sort()
# Check for triangular inequality
   if[(x, y, z) for x, y, z in Alist if (x + y) >= z]:
      print("The sublist showing triangular inequality: \n",x)
Running the above code gives us the following result −
The sublist showing triangular inequality:
[6, 8, 9]
RANK() Function in SQL Server - GeeksforGeeks

18 Sep, 2020
The RANK() function is a window function could be used in SQL Server to calculate a rank for each row within a partition of a result set. 
The same rank is assigned to the rows in a partition which have the same values. The rank of the first row is 1. The ranks may not be consecutive in the RANK() function as it adds the number of repeated rows to the repeated rank to calculate the rank of the next row. 
Syntax :  
RANK() OVER (
   [PARTITION BY expression, ]
   ORDER BY expression (ASC | DESC) );


Example – Let us create a table geek_demo that has only column Name : 
 
CREATE TABLE geek_demo (Name VARCHAR(10) );


Now, insert some rows into the sales.rank_demo table : INSERT INTO geek_demo (Name) 
 
VALUES('A'), ('B'), ('B'), ('C'), ('C'), ('D'), ('E');


Select data from the geek_demo table :  
SELECT * 
FROM sales.geek_demo; 

 
Let us use RANK() to assign ranks to the rows in the result set of geek_demo table : 
 
SELECT Name, 
RANK () OVER (
ORDER BY Name
) AS Rank_no 
FROM geek_demo;


Output – 
 
khushboogoyal499
DBMS-SQL
SQL-Server
SQL
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
SQL Trigger | Student Database
SQL | Views
Difference between DDL and DML in DBMS
How to Alter Multiple Columns at Once in SQL Server?
CTE in SQL
SQL Interview Questions
How to Update Multiple Columns in Single Update Statement in SQL?
Difference between DELETE, DROP and TRUNCATE
SQL | GROUP BY
MySQL | Group_CONCAT() Function
How to append a second list to an existing list in C#?

Use the AddRange() method to append a second list to an existing list.
Here is list one −
List < string > list1 = new List < string > ();

list1.Add("One");
list1.Add("Two");
Here is list two −
List < string > list2 = new List < string > ();

list2.Add("Three");
ist2.Add("Four");
Now let us append −
list1.AddRange(list2);
Let us see the complete code.
using System;
using System.Collections.Generic;
using System.Linq;

public class Demo {
   public static void Main() {

      List < string > list1 = new List < string > ();
      list1.Add("One");
      list1.Add("Two");
      Console.WriteLine("First list...");
      foreach(string value in list1) {
         Console.WriteLine(value);
      }

      Console.WriteLine("Second list...");
      List < string > list2 = new List < string > ();

      list2.Add("Three");
      list2.Add("Four");
      foreach(string value in list2) {
         Console.WriteLine(value);
      }

      Console.WriteLine("After Append...");
      list1.AddRange(list2);
      foreach(string value in list1) {
         Console.WriteLine(value);
      }
   }
}
Tryit Editor v3.6 - Show Java

class Vehicle  // Base class
  {
    public string brand = "Ford";  // Vehicle field
    public void honk()             // Vehicle method 
    {
      Console.WriteLine("Tuut, tuut!");
    }
  }
}


using System;

namespace MyApplication
{
  class Car : Vehicle  // Derived class
  {
    public string modelName = "Mustang";  // Car field
  }
}


using System;

namespace MyApplication
{
  class Program
  { 
    static void Main(string[] args)
    {
      // Create a myCar object
      Car myCar = new Car();

      // Call the honk() method (From the Vehicle class) on the myCar object
      myCar.honk();

      // Display the value of the brand field (from the Vehicle class) and the value of the modelName from the Car class
      Console.WriteLine(myCar.brand + " " + myCar.modelName);
PySpark - SparkFiles

In Apache Spark, you can upload your files using sc.addFile (sc is your default SparkContext) and get the path on a worker using SparkFiles.get. Thus, SparkFiles resolve the paths to files added through SparkContext.addFile().
SparkFiles contain the following classmethods −
get(filename)
getrootdirectory()
Let us understand them in detail.
It specifies the path of the file that is added through SparkContext.addFile().
It specifies the path to the root directory, which contains the file that is added through the SparkContext.addFile().
----------------------------------------sparkfile.py------------------------------------
from pyspark import SparkContext
from pyspark import SparkFiles
finddistance = "/home/hadoop/examples_pyspark/finddistance.R"
finddistancename = "finddistance.R"
sc = SparkContext("local", "SparkFile App")
sc.addFile(finddistance)
print "Absolute Path -> %s" % SparkFiles.get(finddistancename)
----------------------------------------sparkfile.py------------------------------------

Command − The command is as follows −
$SPARK_HOME/bin/spark-submit sparkfiles.py

Output − The output for the above command is −
Absolute Path -> 
   /tmp/spark-f1170149-af01-4620-9805-f61c85fecee4/userFiles-641dfd0f-240b-4264-a650-4e06e7a57839/finddistance.R

 Print
 Add Notes
 Bookmark this page
How do you dynamically add Python modules to a package while your programming is running?

To dynamically import Python modules, you can use the importlib package's import_module(moduleName) function. You need to have moduleName as a string. For example,
>>> from importlib import import_module
>>> moduleName = "os"
>>> globals()[moduleName] = import_module(moduleName)
If you want to dynamically import a list of modules, you can even call this from a for loop. For example,
>>> import importlib
>>> modnames = ["os", "sys", "math"]
>>> for lib in modnames:
...     globals()[lib] = importlib.import_module(lib)
The globals() call returns a dict. We can set the lib key for each library as the object returned to us on import of a module.
If you've imported a package and now want to dynamically import one of its module, you can still use the same function and get the expected result. The module you want to import should have its full name and not just the module name. For example,
>>> import importlib
>>> pack = 'datetime'
>>> mod = 'date'
>>> globals()[pack] = importlib.import_module(pack)
>>> globals()[pack + '.' + mod] = importlib.import_module(pack + '.' + mod)
How to create a "section counter" with CSS?

To create a section counter with CSS, the code is as follows −
 Live Demo
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/fontawesome.min.css">
<style>
   * {
      box-sizing: border-box;
   }
   body {
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif
   }
   .section {
      float: left;
      width: 25%;
      padding: 0 5px;
   }
   .sectionContainer {margin: 0 -5px;}
   .sectionContainer:after {
      content: "";
      display: table;
      clear: both;
   }
   @media screen and (max-width: 600px) {
      .section {
         width: 100%;
         display: block;
         margin-bottom: 10px;
      }
   }
   .sectionCard {
      box-shadow: 0 4px 8px 0 rgb(127, 16, 172);
      padding: 16px;
      text-align: center;
      background-color: rgb(127, 16, 172);
      color: rgb(255, 255, 255);
   }
   .fa {font-size:50px;}
</style>
</head>
<body>
<h1>Responsive Section Counter Example</h1>
<br>
<div class="sectionContainer">
<div class="section">
<div class="sectionCard">
<p><i class="fa fa-mobile" aria-hidden="true"></i></p>
<h3>100000+</h3>
<p>Downloads</p>
</div>
</div>
<div class="section">
<div class="sectionCard">
<p><i class="fa fa-globe" aria-hidden="true"></i></p>
<h3>5000+</h3>
<p>Outlets over the globe</p>
</div>
</div>
<div class="section">
<div class="sectionCard">
<p><i class="fa fa-bar-chart" aria-hidden="true"></i> </p>
<h3>Top Performer</h3>
<p>In past 5 years</p>
</div>
</div>
<div class="section">
<div class="sectionCard">
<p><i class="fa fa-handshake-o" aria-hidden="true"></i></p>
<h3>3000+</h3>
<p>Partners</p>
</div>
</div>
</div>
</body>
</html>
The above code will produce the following output −
On resizing the screen −
PL/SQL - GOTO Statement

A GOTO statement in PL/SQL programming language provides an unconditional jump from the GOTO to a labeled statement in the same subprogram.
NOTE − The use of GOTO statement is not recommended in any programming language because it makes it difficult to trace the control flow of a program, making the program hard to understand and hard to modify. Any program that uses a GOTO can be rewritten so that it doesn't need the GOTO.
The syntax for a GOTO statement in PL/SQL is as follows −
GOTO label;
..
..
<< label >>
statement;

DECLARE 
   a number(2) := 10; 
BEGIN 
   <<loopstart>> 
   -- while loop execution  
   WHILE a < 20 LOOP
   dbms_output.put_line ('value of a: ' || a); 
      a := a + 1; 
      IF a = 15 THEN 
         a := a + 1; 
         GOTO loopstart; 
      END IF; 
   END LOOP; 
END; 
/
When the above code is executed at the SQL prompt, it produces the following result −
value of a: 10 
value of a: 11 
value of a: 12 
value of a: 13 
value of a: 14 
value of a: 16 
value of a: 17 
value of a: 18 
value of a: 19  

PL/SQL procedure successfully completed.

GOTO Statement in PL/SQL imposes the following restrictions −
A GOTO statement cannot branch into an IF statement, CASE statement, LOOP statement or sub-block.
A GOTO statement cannot branch into an IF statement, CASE statement, LOOP statement or sub-block.
A GOTO statement cannot branch from one IF statement clause to another or from one CASE statement WHEN clause to another.
A GOTO statement cannot branch from one IF statement clause to another or from one CASE statement WHEN clause to another.
A GOTO statement cannot branch from an outer block into a sub-block (i.e., an inner BEGIN-END block).
A GOTO statement cannot branch from an outer block into a sub-block (i.e., an inner BEGIN-END block).
A GOTO statement cannot branch out of a subprogram. To end a subprogram early, either use the RETURN statement or have GOTO branch to a place right before the end of the subprogram.
A GOTO statement cannot branch out of a subprogram. To end a subprogram early, either use the RETURN statement or have GOTO branch to a place right before the end of the subprogram.
A GOTO statement cannot branch from an exception handler back into the current BEGIN-END block. However, a GOTO statement can branch from an exception handler into an enclosing block.
A GOTO statement cannot branch from an exception handler back into the current BEGIN-END block. However, a GOTO statement can branch from an exception handler into an enclosing block.
 Print
 Add Notes
 Bookmark this page
Calculate average of numbers in a column MySQL query?

Calculate the average of numbers in a column with the help of MySQL aggregate function AVG().
The syntax is as follows −
select avg(yourColumnName) as anyVariableName from yourTableName;
To understand the above concept, let us create a table. The following is the query to create a table.
mysql> create table AverageCalculateDemo
   −> (
      −> SubjectMarks int
   −> );
Query OK, 0 rows affected (0.67 sec)
The following is the query to insert some records into the table −
mysql> insert into AverageCalculateDemo values(70);
Query OK, 1 row affected (0.14 sec)

mysql> insert into AverageCalculateDemo values(80);
Query OK, 1 row affected (0.19 sec)

mysql> insert into AverageCalculateDemo values(65);
Query OK, 1 row affected (0.13 sec)

mysql> insert into AverageCalculateDemo values(55);
Query OK, 1 row affected (0.13 sec)

mysql> insert into AverageCalculateDemo values(60);
Query OK, 1 row affected (0.23 sec)
Display all values with the help of a select statement. The query is as follows to display all records −
mysql> select *from AverageCalculateDemo;
The following is the output −
+--------------+
| SubjectMarks |
+--------------+
|           70 |
|           80 |
|           65 |
|           55 |
|           60 |
+--------------+
5 rows in set (0.00 sec)
Here is the query that calculates the average of the column in MySQL −
mysql> select avg(SubjectMarks) as AverageOf4Numbers from AverageCalculateDemo;
The following is the output that displays the average −
+-------------------+
| AverageOf4Numbers |
+-------------------+
| 66.0000           |
+-------------------+
1 row in set (0.00 sec)
How to handle error object in JSP using JSTL tags?

You can make use of JSTL tags to write an error page ShowError.jsp with better structure and more information −
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<%@page isErrorPage = "true" %>

<html>
   <head>
      <title>Show Error Page</title>
   </head>
   <body>
      <h1>Opps...</h1>
      <table width = "100%" border = "1">
         <tr valign = "top">
            <td width = "40%"><b>Error:</b></td>
            <td>${pageContext.exception}</td>
         </tr>
         <tr valign = "top">
            <td><b>URI:</b></td>
            <td>${pageContext.errorData.requestURI}</td>
         </tr>
         <tr valign = "top">
            <td><b>Status code:</b></td>
            <td>${pageContext.errorData.statusCode}</td>
         </tr>
         <tr valign = "top">
            <td><b>Stack trace:</b></td>
            <td>
               <c:forEach var = "trace"
                  items = "${pageContext.exception.stackTrace}">
                  <p>${trace}</p>
               </c:forEach>
            </td>
         </tr>
      </table>
   </body>
</html>
Access the main.jsp, the following will be generated −
XQuery - XPath

XQuery is XPath compliant. It uses XPath expressions to restrict the search results on XML collections. For more details on how to use XPath, see our XPath Tutorial.
Recall the following XPath expression which we have used earlier to get the list of books.
doc("books.xml")/books/book
We will use the books.xml file and apply XQuery to it.
<?xml version="1.0" encoding="UTF-8"?>
<books>
   
   <book category="JAVA">
      <title lang="en">Learn Java in 24 Hours</title>
      <author>Robert</author>
      <year>2005</year>
      <price>30.00</price>
   </book>
   
   <book category="DOTNET">
      <title lang="en">Learn .Net in 24 hours</title>
      <author>Peter</author>
      <year>2011</year>
      <price>40.50</price>
   </book>
   
   <book category="XML">
      <title lang="en">Learn XQuery in 24 hours</title>
      <author>Robert</author>
      <author>Peter</author> 
      <year>2013</year>
      <price>50.00</price>
   </book>
   
   <book category="XML">
      <title lang="en">Learn XPath in 24 hours</title>
      <author>Jay Ban</author>
      <year>2010</year>
      <price>16.50</price>
   </book>
   
</books>
We have given here three versions of an XQuery statement that fulfil the same objective of displaying the book titles having a price value greater than 30.
(: read the entire xml document :)
let $books := doc("books.xml")

for $x in $books/books/book
where $x/price > 30
return $x/title
<title lang="en">Learn .Net in 24 hours</title>
<title lang="en">Learn XQuery in 24 hours</title>

(: read all books :)
let $books := doc("books.xml")/books/book

for $x in $books
where $x/price > 30
return $x/title
<title lang="en">Learn .Net in 24 hours</title>
<title lang="en">Learn XQuery in 24 hours</title>

(: read books with price > 30 :)
let $books := doc("books.xml")/books/book[price > 30]

for $x in $books
return $x/title
<title lang="en">Learn .Net in 24 hours</title>
<title lang="en">Learn XQuery in 24 hours</title>

To verify the result, replace the contents of books.xqy (given in the Environment Setup chapter) with the above XQuery expression and execute the XQueryTester java program.
 Print
 Add Notes
 Bookmark this page
Groovy - Regular Expressions

A regular expression is a pattern that is used to find substrings in text. Groovy supports regular expressions natively using the ~”regex” expression. The text enclosed within the quotations represent the expression for comparison.
For example we can create a regular expression object as shown below −
def regex = ~'Groovy'

When the Groovy operator =~ appears as a predicate (expression returning a Boolean) in if and while statements (see Chapter 8), the String operand on the left is matched against the regular expression operand on the right. Hence, each of the following delivers the value true.
When defining regular expression, the following special characters can be used −
There are two special positional characters that are used to denote the beginning and end of a line: caret (∧) and dollar sign ($).
There are two special positional characters that are used to denote the beginning and end of a line: caret (∧) and dollar sign ($).
Regular expressions can also include quantifiers. The plus sign (+) represents one or more times, applied to the preceding element of the expression. The asterisk (*) is used to represent zero or more occurrences. The question mark (?) denotes zero or once.
Regular expressions can also include quantifiers. The plus sign (+) represents one or more times, applied to the preceding element of the expression. The asterisk (*) is used to represent zero or more occurrences. The question mark (?) denotes zero or once.
The metacharacter { and } is used to match a specific number of instances of the preceding character.
The metacharacter { and } is used to match a specific number of instances of the preceding character.
In a regular expression, the period symbol (.) can represent any character. This is described as the wildcard character.
In a regular expression, the period symbol (.) can represent any character. This is described as the wildcard character.
A regular expression may include character classes. A set of characters can be given as a simple sequence of characters enclosed in the metacharacters [and] as in [aeiou]. For letter or number ranges, you can use a dash separator as in [a–z] or [a–mA–M]. The complement of a character class is denoted by a leading caret within the square rackets as in [∧a–z] and represents all characters other than those specified. Some examples of Regular expressions are given below
A regular expression may include character classes. A set of characters can be given as a simple sequence of characters enclosed in the metacharacters [and] as in [aeiou]. For letter or number ranges, you can use a dash separator as in [a–z] or [a–mA–M]. The complement of a character class is denoted by a leading caret within the square rackets as in [∧a–z] and represents all characters other than those specified. Some examples of Regular expressions are given below
'Groovy' =~ 'Groovy' 
'Groovy' =~ 'oo' 
'Groovy' ==~ 'Groovy' 
'Groovy' ==~ 'oo' 
'Groovy' =~ '∧G' 
‘Groovy' =~ 'G$' 
‘Groovy' =~ 'Gro*vy' 'Groovy' =~ 'Gro{2}vy'


    52 Lectures 
     8 hours 

 Krishna Sakinala

    49 Lectures 
     2.5 hours 

 Packt Publishing
 Print
 Add Notes
 Bookmark this page
Binding function in Python Tkinter

In python tkinter is a GUI library that can be used for various GUI programming. Such applications are useful to build desktop applications. In this article we will see one aspect of the GUI programming called Binding functions. This is about binding events to functions and methods so that when the event occurs that specific function is executed.
In the below example we bind the press of any key from the keyboard with a function that gets executed. Once the Tkinter GUI window is open, we can press any key in the keyboard and we get a message that the keyboard is pressed.
from tkinter import *

# Press a buton in keyboard
def PressAnyKey(label):
   value = label.char
   print(value, ' A button is pressed')

base = Tk()
base.geometry('300x150')
base.bind('<Key>', lambda i : PressAnyKey(i))
mainloop()

Running the above code gives us the following result −
In the below example we see how to bind the mouse click events on a tkinter window to a function call. In the below example we call the events to display the left-button double click, right button click and scroll-button click to display the position in the tkinter canvas where the buttons were clicked.
from tkinter import *
from tkinter.ttk import *

# creates tkinter window or root window
base = Tk()
base.geometry('300x150')

# Press the scroll button in the mouse then function will be called
def scroll(label):
   print('Scroll button clicked at x = % d, y = % d'%(label.x, label.y))
# Press the right button in the mouse then function will be called
def right_click(label):
   print('right button clicked at x = % d, y = % d'%(label.x, label.y))
# Press the left button twice in the mouse then function will be called
def left_click(label):
   print('Double clicked left button at x = % d, y = % d'%(label.x, label.y))

Function = Frame(base, height = 100, width = 200)
Function.bind('<Button-2>', scroll)
Function.bind('<Button-3>', right_click)
Function.bind('<Double 1>', left_click)
Function.pack()
mainloop()
Running the above code gives us the following result −
Does C++ compiler create default constructor when we write our own?

In this tutorial, we will be discussing a program to understand if the C++ compiler creates a default constructor when we write our own.
Generally, the C++ compiler uses the default constructor when no one is defined, but always uses the one defined by the user if any.
 Live Demo
#include<iostream>
using namespace std;
class myInteger{
private:
   int value;
   //other functions in class
};
int main(){
   myInteger I1;
   getchar();
   return 0;
}
Compiles successfully
#include<iostream>
using namespace std;
class myInteger{
   private:
      int value;
   public:
      myInteger(int v) //user-defined constructor
   { value = v; }
   //other functions in class
};
int main(){
   myInteger I1;
   getchar();
   return 0;
}
Gives error about user-defined constructor not being defined
Function to find the length of the second smallest word in a string in JavaScript

We are required to write a JavaScript function that takes in a string sentence as first and the only argument. And the function should return the length of the second smallest word from the
string.
For example: If the string is −
const str = 'This is a sample string';
Then the output should be 2.
Therefore, let’s write the code for this function −
The code for this will be −
const str = 'This is a sample string';
const secondSmallest = str => {
   const strArr = str.split(' ');
   if(strArr.length < 2){
      return false;
   }
   for(let i = 0; i < strArr.length; i++){
      strArr[i] = strArr[i].length;
   };
   strArr.sort((a, b) => a - b);
      return strArr[1];
};
console.log(secondSmallest(str));
The output in the console will be −
2
Swing Examples - Creating Radio Button Group

Following example showcase how to use standard radio buttons in a group in a Java Swing application.
We are using the following APIs.
ButtonGroup − To create a Button group.
ButtonGroup − To create a Button group.
ButtonGroup.add(); − To add a radio button to a group.
ButtonGroup.add(); − To add a radio button to a group.
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class SwingTester {
   public static void main(String[] args) {
      createWindow();
   }

   private static void createWindow() {    
      JFrame frame = new JFrame("Swing Tester");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      createUI(frame);
      frame.setSize(560, 200);      
      frame.setLocationRelativeTo(null);  
      frame.setVisible(true);
   }

   private static void createUI(final JFrame frame){  
      JPanel panel = new JPanel();
      LayoutManager layout = new FlowLayout();  
      panel.setLayout(layout);       

      JRadioButton radioButton1 = new JRadioButton("Radio Button 1");
      JRadioButton radioButton2 = new JRadioButton("Radio Button 2");
      JRadioButton radioButton3 = new JRadioButton("Radio Button 3");

      ButtonGroup group = new ButtonGroup();
      group.add(radioButton1);
      group.add(radioButton2);
      group.add(radioButton3);

      panel.add(radioButton1);
      panel.add(radioButton2);
      panel.add(radioButton3);
      frame.getContentPane().add(panel, BorderLayout.CENTER);    
   }
}
 Print
 Add Notes
 Bookmark this page
Converting degree to radian in JavaScript

The radian is the unit for measuring angles and is the standard unit of angular measure used in many areas of mathematics.
We are required to write a JavaScript function that takes in a number that represents some degree and returns its corresponding radian.
Following is the code −
const deg = 180;
const degreeToRadian = (degree) => {
   const factor = (Math.PI / 180);
   const rad = degree / factor;
   return rad;
};
console.log(degreeToRadian(deg));
Following is the output on console −
10313.240312354817
Showing points coordinates in a plot in Python using Matplotlib

To show points coordinate in a plot in Python, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Create lists of x and y data points.
Plot x and y data points with red color and starred marker
Set some axis properties.
Iterate x and y to show the coordinates on the plot.
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

x = [3, 1, 2, 5]
y = [5, 2, 4, 7]

plt.plot(x, y, 'r*')
plt.axis([0, 6, 0, 20])

for i, j in zip(x, y):
   plt.text(i, j+0.5, '({}, {})'.format(i, j))

plt.show()
Data Structure and Algorithms Insertion Sort

This is an in-place comparison-based sorting algorithm. Here, a sub-list is maintained which is always sorted. For example, the lower part of an array is maintained to be sorted. An element which is to be 'insert'ed in this sorted sub-list, has to find its appropriate place and then it has to be inserted there. Hence the name, insertion sort.
The array is searched sequentially and unsorted items are moved and inserted into the sorted sub-list (in the same array). This algorithm is not suitable for large data sets as its average and worst case complexity are of Ο(n2), where n is the number of items.
We take an unsorted array for our example.
Insertion sort compares the first two elements.
It finds that both 14 and 33 are already in ascending order. For now, 14 is in sorted sub-list.
Insertion sort moves ahead and compares 33 with 27.
And finds that 33 is not in the correct position.
It swaps 33 with 27. It also checks with all the elements of sorted sub-list. Here we see that the sorted sub-list has only one element 14, and 27 is greater than 14. Hence, the sorted sub-list remains sorted after swapping.
By now we have 14 and 27 in the sorted sub-list. Next, it compares 33 with 10.
These values are not in a sorted order.
So we swap them.
However, swapping makes 27 and 10 unsorted.
Hence, we swap them too.
Again we find 14 and 10 in an unsorted order.
We swap them again. By the end of third iteration, we have a sorted sub-list of 4 items.
This process goes on until all the unsorted values are covered in a sorted sub-list. Now we shall see some programming aspects of insertion sort.
Now we have a bigger picture of how this sorting technique works, so we can derive simple steps by which we can achieve insertion sort.
Step 1 − If it is the first element, it is already sorted. return 1;
Step 2 − Pick next element
Step 3 − Compare with all elements in the sorted sub-list
Step 4 − Shift all the elements in the sorted sub-list that is greater than the 
         value to be sorted
Step 5 − Insert the value
Step 6 − Repeat until list is sorted

procedure insertionSort( A : array of items )
   int holePosition
   int valueToInsert
	
   for i = 1 to length(A) inclusive do:
	
      /* select value to be inserted */
      valueToInsert = A[i]
      holePosition = i
      
      /*locate hole position for the element to be inserted */
		
      while holePosition > 0 and A[holePosition-1] > valueToInsert do:
         A[holePosition] = A[holePosition-1]
         holePosition = holePosition -1
      end while
		
      /* insert the number at hole position */
      A[holePosition] = valueToInsert
      
   end for
	
end procedure
To know about insertion sort implementation in C programming language, please click here.

    42 Lectures 
     1.5 hours 

 Ravi Kiran

    141 Lectures 
     13 hours 

 Arnab Chakraborty

    26 Lectures 
     8.5 hours 

 Parth Panjabi

    65 Lectures 
     6 hours 

 Arnab Chakraborty

    75 Lectures 
     13 hours 

 Eduonix Learning Solutions

    64 Lectures 
     10.5 hours 

 Eduonix Learning Solutions
 Print
 Add Notes
 Bookmark this page