code-rag-bench/online-tutorials huggingface dataset:
jQuery | event.stopPropagation() Method - GeeksforGeeks

17 Jul, 2019
The event.stopPropagation() method is an inbuilt method in jQuery which is used to stop the windows propagation. In the DOM tree when setting an event with the child element and the parent element as well then if you hit on the child element event it will call both child and the parent element as well. So with the help of this method this popup will not appear for the other element except selected element.
Syntax:
event.stopPropagation()
Parameters: It accepts single parameter which is mandatory. This parameter comes from binding function.
Return Value: This method returns the selected element with specified changes made by stopPropagation() method.
Example: This example illustrates the event.stopPropagation() method.
<!DOCTYPE html><html>   <head>    <title>        jQuery event.stopPropagation() Method    </title>          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">    </script>          <style>        .main {            border:1px solid green;            padding:20px;            width:60%;        }    </style>          <!-- Script to use jQuery event.stopPropagation() Method -->    <script>        $(document).ready(function() {            $(".main").click(function() {                alert("Main div element");            });            $(".GFG").click(function(event) {                event.stopPropagation();                alert("Nested div element");            });            $(".geeks").click(function(event) {                alert("Second nested div element");            });        });    </script></head>   <body>          <!-- Click on element to display alert message -->    <div class="main">        GeeksforGeeks        <div class="GFG">            A computer science portal            <div class="geeks">                Welcome to GeeksforGeeks            </div>        </div>    </div>   </body>   </html>
Output:
Before Clicking the button:
After Clicking the button:
jQuery-Events
Picked
JQuery
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Scroll to the top of the page using JavaScript/jQuery
How to get the ID of the clicked button using JavaScript / jQuery ?
jQuery | children() with Examples
How to check whether a checkbox is checked in jQuery?
jQuery | ajax() Method
Installation of Node.js on Linux
Roadmap to Become a Web Developer in 2022
How to fetch data from an API in ReactJS ?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?
How to scale down an image with CSS to make it responsive

To make an image responsive, you can try to run the following code:
Live Demo
<!DOCTYPE html>
<html>
   <head>
      <style>
         img {
            max-width: 100%;
            height: auto;
         }
      </style>
   </head>
   <body>
      <img src = "https://www.tutorialspoint.com/videotutorials/images/coding_ground_home.jpg" alt = "Online Compiler" width = "300" height = "300">
   </body>
</html>
Draw a filled polygon using the OpenCV function fillPoly()

In this program, we will draw a filled polygon using the opencv function fillPoly(). The function takes in an image and the endpoints of the polygon.
Step 1: Import cv2 and numpy.
Step 2: Define the endpoints.
Step 3: Define the image using zeros.
Step 4: Draw the polygon using the fillpoly() function.
Step 5: Display the output.
import cv2
import numpy as np
contours = np.array([[50,50], [50,150], [150,150], [150,50]])
image = np.zeros((200,200))
cv2.fillPoly(image, pts = [contours], color =(255,255,255))
cv2.imshow("filledPolygon", image)
Tryit Editor v3.7

Tryit: HTML rgba color values
Create a mirror tree from the given binary tree in C++ Program

In this tutorial, we are going to reflect the given binary tree.
Let's see the steps to solve the problem.
Write a struct node.
Write a struct node.
Create the binary tree with dummy data.
Create the binary tree with dummy data.
Write a recursive function to find the mirror of the given binary tree.Recursively call the function with left and right nodes.Swap the left node data with the right node data.
Write a recursive function to find the mirror of the given binary tree.
Recursively call the function with left and right nodes.
Recursively call the function with left and right nodes.
Swap the left node data with the right node data.
Swap the left node data with the right node data.
Print the tree.
Print the tree.
Let's see the code.
 Live Demo
#include<bits/stdc++.h>
using namespace std;
struct Node {
   int data;
   struct Node* left;
   struct Node* right;
};
struct Node* newNode(int data) {
   struct Node* node = new Node;
   node->data = data;
   node->left = NULL;
   node->right = NULL;
   return node;
}
void convertTreeToItsMirror(struct Node* node) {
   if (node == NULL) {
      return;
   }
   else {
      struct Node* temp;
      convertTreeToItsMirror(node->left);
      convertTreeToItsMirror(node->right);
      temp = node->left;
      node->left = node->right;
      node->right = temp;
   }
}
void printTree(struct Node* node) {
   if (node == NULL) {
      return;
   }
   printTree(node->left);
   cout << node->data << " ";
   printTree(node->right);
}
int main() {
   struct Node *root = newNode(1);
   root->left = newNode(2);
   root->right = newNode(3);
   root->left->left = newNode(4);
   root->left->right = newNode(5);
   cout << "Tree: ";
   printTree(root);
   cout << endl;
   convertTreeToItsMirror(root);
   cout << "Mirror of the Tree: ";
   printTree(root);
   cout << endl;
   return 0;
}
If you run the above code, then you will get the following result.
Tree: 4 2 5 1 3
Mirror of the Tree: 3 1 5 2 4
If you have any queries in the tutorial, mention them in the comment section.
PyQt5 Label – Make shadow disappear according to user - GeeksforGeeks

10 May, 2020
In this article we will see how we can make the shadow disappear of the label according to the user. Shadow will be shown and disappear when user make the radio button checked and will appear when radio button is unchecked.
In order to do this we use setEnabled method
Syntax : shadow.setEnabled(bool)
Argument : It takes bool as argument
Return : None
Below is the implementation
# importing librariesfrom PyQt5.QtWidgets import * from PyQt5 import QtCore, QtGuifrom PyQt5.QtGui import * from PyQt5.QtCore import * import sys    class Window(QMainWindow):      def __init__(self):        super().__init__()          # setting title        self.setWindowTitle("Python ")          # setting geometry        self.setGeometry(100, 100, 600, 400)          # calling method        self.UiComponents()          # showing all the widgets        self.show()      # method for widgets    def UiComponents(self):          # creating label        label = QLabel("Label", self)          # setting alignment        label.setAlignment(Qt.AlignCenter)          # setting geometry to the label        label.setGeometry(200, 100, 150, 60)          # setting border        label.setStyleSheet("border : 8px solid black")          # creating a QGraphicsDropShadowEffect object        self.shadow = QGraphicsDropShadowEffect()          # setting blur radius        self.shadow.setBlurRadius(30)          # setting Xoffset        self.shadow.setOffset(10)          # adding shadow to the label        label.setGraphicsEffect(self.shadow)          # creating radio button        self.button = QRadioButton("Hide Shadow", self)          # setting geometry to the radio button        self.button.setGeometry(200, 200, 100, 40)          # adding action to the button        self.button.clicked.connect(self.hide_shadow)      def hide_shadow(self):          if self.button.isChecked():              # making shadow off            self.shadow.setEnabled(False)          else:            # making shadow off            self.shadow.setEnabled(True)    # create pyqt5 appApp = QApplication(sys.argv)  # create the instance of our Windowwindow = Window()  # start the appsys.exit(App.exec())
Output :
Python PyQt5-Label
Python-gui
Python-PyQt
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Read a file line by line in Python
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
Iterate over a list in Python
Python String | replace()
*args and **kwargs in Python
Reading and Writing to text files in Python
Create a Pandas DataFrame from Lists
Python | Add dictionary to tuple - GeeksforGeeks

04 Aug, 2021
Sometimes, while working with data, we can have a problem in which we need to append to a tuple a new record which is of form of Python dictionary. This kind of application can come in web development domain in case of composite attributes. Let’s discuss certain ways in which this task can be performed.Method #1 : Using list() + append + tuple() This method can be used to solve this problem. In this, we just convert the tuple into a list and then perform list append and then reconvert the list to tuple using tuple().
 Example :
Python3
# Python3 code to demonstrate working of# Add dictionary to tuple# using append() + tuple() + list comprehension # initialize tupletest_tup = (4, 5, 6) # printing original tupleprint("The original tuple : " + str(test_tup)) # initialize dictionarytest_dict = {"gfg" : 1, "is" : 2, "best" : 3} # Add dictionary to tuple# using append() + tuple() + list comprehensiontest_tup = list(test_tup)test_tup.append(test_dict)test_tup = tuple(test_tup) # printing resultprint("Tuple after addition of dictionary : " + str(test_tup))
The original tuple : (4, 5, 6)
Tuple after addition of dictionary : (4, 5, 6, {'best': 3, 'is': 2, 'gfg': 1})
 
 Method #2 : Using + operator This is another way to perform this task. In this, we add dictionary to different tuple and then add the old tuple to this tuple and form new tuple. Key difference is that this is not inplace addition as upper method, but creates new tuple out of old one. 
 Example :
Python3
# Python3 code to demonstrate working of# Add dictionary to tuple# using + operator # initialize tupletest_tup = (4, 5, 6) # printing original tupleprint("The original tuple : " + str(test_tup)) # initialize dictionarytest_dict = {"gfg" : 1, "is" : 2, "best" : 3} # Add dictionary to tuple# using + operatorres = test_tup + (test_dict, ) # printing resultprint("Tuple after addition of dictionary : " + str(res))
The original tuple : (4, 5, 6)
Tuple after addition of dictionary : (4, 5, 6, {'best': 3, 'is': 2, 'gfg': 1})
 
simmytarika5
Python tuple-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Check if element exists in list in Python
How To Convert Python Dictionary To JSON?
Python Classes and Objects
How to drop one or multiple columns in Pandas Dataframe
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Split string into list of characters
Python | Convert a list to dictionary
How to print without newline in Python?
Python | Find fibonacci series upto n using lambda - GeeksforGeeks

17 Mar, 2019
The Fibonacci numbers are the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ........
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation
Fn = Fn-1 + Fn-2  with seed values   F0 = 0 and F1 = 1.
Find the series of fibonacci numbers using lambda function.
Code #1 : By using lambda and reduce method
from functools import reduce  fib = lambda n: reduce(lambda x, _: x+[x[-1]+x[-2]],                                 range(n-2), [0, 1])  print(fib(5))
[0, 1, 1, 2, 3]

Explanation :
The list taking first two parameters is 0 and 1, and add like x[-1] i.e 0 and x[-2] i.e 1 and append to variable x. There is a type conversion to list and due to reduce() method, the same function calls and due to range function this time parameter changes, then add this to previous result and again store it to list. 
Code #2 : By using lambda and map function
def fibonacci(count):    fib_list = [0, 1]      any(map(lambda _: fib_list.append(sum(fib_list[-2:])),                                         range(2, count)))      return fib_list[:count]  print(fibonacci(10))
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

Explanation :We are taking the list fib_list which already has 0 and 1. Then in the next iteration, this will be used as input and result of their sum will append to the list.
Fibonacci
python-lambda
Python
Python Programs
Fibonacci
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
Python String | replace()
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Split string into list of characters
Python | Convert a list to dictionary
How to print without newline in Python?
CSS | element > element Selector - GeeksforGeeks

03 Jan, 2019
The element > element selector in CSS is used to style only those elements which are the children of specific parent.
The operand on the left of > is the parent and the operand on the right is the children element.
Note: Elements that are not directly a child of the specified parent, are not selected.
Syntax:
element1 > element2 {
    //CSS Property
}

Example 1:
<!DOCTYPE html><html>    <head>        <title>        CSS element>element Selector        </title>        <style>            div > p {                color:white;                background: green;                padding:2px;            }        </style>    </head>    <body style = "text-align: center;">        <div>            <h2 style = "color:green;">                CSS element > element Selector            </h2>                          <p>                A computer science portal for geeks.            </p>        </div>                  <p>Geeks Classes is a quick course to cover         algorithms questions.</p>                  <p>This paragraph will not be styled.</p>    </body></html>
Output:Example 2:
<!DOCTYPE html><html>    <head>        <title>            CSS element > element Selector        </title>        <style>            p > span {                color:white;                background: green;            }        </style>    </head>    <body style = "text-align: center;">        <h1 style = "color:green;">            GeeksforGeeks        </h1>        <h2>            CSS element > element Selector          </h2>                  <p>A computer science <span>portal for geeks.</span></p></body></html>
Output:
Supported Browsers: The browser supported by element > element selector are listed below:
Apple Safari
Google Chrome
Firefox
Opera
Internet Explorer 7.0
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.
CSS-Properties
CSS
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to insert spaces/tabs in text using HTML/CSS?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to update Node.js and NPM to next version ?
How to create footer to stay at the bottom of a Web page?
How to apply style to parent if it has child with CSS?
How to insert spaces/tabs in text using HTML/CSS?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to update Node.js and NPM to next version ?
How to set the default value for an HTML <select> element ?
Hide or show elements in HTML using display property
GATE | GATE-CS-2015 (Set 2) | Question 65 - GeeksforGeeks

28 Jun, 2021
Consider two decision problems Q1, Q2 such that Q1 reduces in polynomial time to 3-SAT and 3-SAT reduces in polynomial time to Q2. Then which one of the following is consistent with the above statement?(A) Q1 is in NP, Q2 is NP hard(B) Q2 is in NP, Q1 is NP hard(C) Both Q1 and Q2 are in NP(D) Both Q1 and Q2 are in NP hardAnswer: (A)Explanation:
Q1 reduces in polynomial time to 3-SAT 
==> Q1 is in NP

3-SAT reduces in polynomial time to Q2 
==> Q2 is NP Hard.  If Q2 can be solved in P, then 3-SAT
    can be solved in P, but 3-SAT is NP-Complete, that makes 
    Q2 NP Hard

Quiz of this Question
GATE-CS-2015 (Set 2)
GATE-GATE-CS-2015 (Set 2)
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GATE | Gate IT 2007 | Question 25
GATE | GATE-CS-2001 | Question 39
GATE | GATE-CS-2000 | Question 41
GATE | GATE-CS-2005 | Question 6
GATE | GATE MOCK 2017 | Question 21
GATE | GATE MOCK 2017 | Question 24
GATE | GATE-CS-2006 | Question 47
GATE | Gate IT 2008 | Question 43
GATE | GATE-CS-2009 | Question 38
GATE | GATE-CS-2003 | Question 90
How to Fix Minimal BASH Like Line Editing is Supported GRUB Error In Linux? - GeeksforGeeks

11 Nov, 2019
GNU GRUB (Stands for GNU GRand Unified Bootloader) is a boot loader package. It is a part of the GNU project. It is the reference implementation of the Free Software Foundation’s Multiboot Specification, that provides a user the choice to boot one of multiple operating systems installed on a computer. It also provides the facility to choose a specific kernel configuration available on a specific OS partition. The Minimal BASH Like Line Editing is Supported GRUB Error In Linux looks like as shown below:
Step 1: Find the partition in which your Linux partition is stored. We can use the ls command to check for available partitions and their filesystem. Linux operating systems usually use ext2/ext3/ext4 filesystems.
grub> ls

This will show us all existing partitions.
Note: If you don’t know which partition has Linux OS then you can check with the ls command as follows:
grub> ls (hdX, Y)

Here, X is disk number and Y is partition name. For Example: grub> ls (hd0, gpt3) or grub> ls (hd1, msdos5)
Step 2: After knowing the partition, set root and prefix variables:
root: Variable which points where the entire Linux OS is installed.
prefix: Variable which points where the GRUB is installed.
grub> set root=(hdX, Y)
grub> set prefix=(hdX, Y)/boot/grub

Step 3: Install normal module and load it:
normal: Linux mod file (linux.mod) used to load kernal. Command used to install mod : insmod
grub> insmod normal

Run this mod file the setup your GRUB:
grub> normal

Step 4: Update GRUB. After entering your Linux OS, reinstall GRUB and update it. Open the terminal and enter following commands:
sudo grub-install /dev/sdXY
sudo update-grub

Here, X is disk number and Y is partition number of EFI partition. If you don’t know which partition is an EFI partition, use Disks or GParted to check.
Restart your PC and the Minimal GRUB error will be solved!!
Linux-Unix
TechTips
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
ZIP command in Linux with examples
TCP Server-Client implementation in C
tar command in Linux with examples
curl command in Linux with Examples
Conditional Statements | Shell Script
How to Find the Wi-Fi Password Using CMD in Windows?
Docker - COPY Instruction
Top Programming Languages for Android App Development
How to Run a Python Script using Docker?
Setting up the environment in Java
typeof Operator Keyword in C#

20 Jun, 2021
The typeof is an operator keyword which is used to get a type at the compile-time. Or in other words, this operator is used to get the System.Type object for a type. This operator takes the Type itself as an argument and returns the marked type of the argument. Important points:  
The operand of typeof operator is always a type of parameter or name of the type. It does not contain variable.
It is not allowed to overload typeof operator.
It is allowed to use typeof operator on open generic types.
It is allowed to use typeof operator on bounded or unbounded types.
Syntax: 
System.Type type = typeof(int);
Here, type is the type that is obtained.Example : 
CSharp
// C# program to illustrate the// concept of typeof operatorusing System; class GFG {     // Here store Type as a field    static Type a = typeof(double);     // Main method    static void Main()    {         // Display the type of a        Console.WriteLine(a);         // Display the value type        Console.WriteLine(typeof(int));         // Display the class type        Console.WriteLine(typeof(Array));         // Display the value type        Console.WriteLine(typeof(char));         // Display the array reference type        Console.WriteLine(typeof(int[]));    }}
Output:  
System.Double
System.Int32
System.Array
System.Char
System.Int32[]
 
 
 
Example: 
CSharp
// C# program to illustrate the// difference between typeof// operator and GetType methodusing System; public class GFG {     // Main method    static public void Main()    {        string s = "Geeks";         // using typeof operator        Type a1 = typeof(string);         // using GetType method        Type a2 = s.GetType();         // checking for equality        Console.WriteLine(a1 == a2);         // taking a type object        object obj = "Hello";         // using typeof operator        Type b1 = typeof(object);         // using GetType method        Type b2 = obj.GetType();         // checking for equality        // it will return False as        // GetType method is used        // to obtain run-time type        Console.WriteLine(b1 == b2);    }}
Output:  
True
False
Explanation: Here, Type b1 = typeof(object); this will return System.Object but Type b2 = obj.GetType(); will return System.String. As, at compile time only object type reference is created, but at runtime the string(“Hello”) is actually storing in it. 
surindertarika1234
CSharp-keyword
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python program to find number of likes and dislikes

30 Jan, 2020
Alice and Bob made a list of topics and both of them voted if they like or dislike the topic. They wrote 0 to denote dislike and 1 to denote like. The task is to count the number of topics that both of them like or dislike.
Examples:
Input: alice = “010101” bob = “101101”Output: 3alice and bob both like 4th and 6th topics and dislike the 5th topic. Hence, the output is 3.
Input: alice = “111111” bob = “000000”Output: 0There are no common likes or dislikes between alice and bob. Hence, the output is 0.
Input: alice = “110000” bob = “110011”Output: 4alice and bob both like 1st and 2nd topics and dislike 3rd and 4th topics. Hence, the result is 4.
Approach:
First, we have to iterate through each character of the string consisting of the likes and dislikes of alice.
Then, we have to compare it with the corresponding entry of the string consisting of the likes and dislikes of bob.
Finally, we will count the number of similar entries and print.
Below is the implementation.
# function to obtain no # of topics both alice and # bob like def commontopics(alice, bob):          # initiate count with 0    count = 0          # iterating through alice    for i in range(0,len(alice)):                  # comparing with corresponding        # bob entry        if alice[i] == bob[i]:                          # counting similar entries            count += 1                   # printing the count             print(count)   #main function def main():          commontopics("010101", "101101")    commontopics("111111", "000000")    commontopics("110000", "110011")        # driver codeif __name__ == "__main__":    main()  # This code is contributed by SrujayReddy
Output:
3
0
4

Python string-programs
python-string
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
Check if element exists in list in Python
Python | os.path.join() method
How To Convert Python Dictionary To JSON?
Python | Get unique values from a list
Defaultdict in Python
How to find standard deviations for all columns of an R data frame?

To find the means of all columns in an R data frame, we can simply use colMeans function and it returns the mean. But for standard deviations, we do not have any direct function that can be used; therefore, we can use sd with apply and reference the columns to find the standard deviations for all column of an R data frame. For example, if we have a data frame df then the syntax using apply function to find the standard deviations for all columns will be apply(df,2,sd), here 2 refers to the columns. If we want to find the standard deviations for rows then we just need to replace this 2 with 1.
Consider the below data frame −
 Live Demo
> set.seed(101)
> x1<-rnorm(20,0.5)
> x2<-rnorm(20,1.5)
> x3<-rnorm(20,2.5)
> df1<-data.frame(x1,x2,x3)
> df1
      x1          x2       x3
1 0.1739635 1.33624433 2.9824588
2 1.0524619 2.20852210 3.2582138
3 -0.1749438 1.23201945 0.1806726
4 0.7143595 0.03607824 2.0404952
5 0.8107692 2.24443582 1.3946163
6 1.6739663 0.08960982 2.9029283
7 1.1187899 1.96706761 3.0689349
8 0.3872657 1.38067989 1.7939167
9 1.4170283 1.96723896 2.2099094
10 0.2767406 1.99813556 1.0161219
11 1.0264481 2.39493720 1.3497447
12 -0.2948444 1.77915200 2.2255288
13 1.9277555 2.50786575 3.0779010
14 -0.9668197 -0.57310649 1.1030974
15 0.2633166 2.68985338 3.2490577
16 0.3066620 0.77562578 1.4488133
17 -0.3497547 1.66798377 2.6653809
18 0.5584655 2.42033516 3.6298091
19 -0.3176704 -0.17160481 3.6737225
20 -1.5503078 1.94846907 2.0721368
Finding the standard deviations of all columns of df1 −
> apply(df1,2,sd)
x1 x2 x3
0.8667844 0.9730288 0.9738892
Let’s have a look at two more examples −
 Live Demo
> y1<-rpois(20,2)
> y2<-rpois(20,5)
> y3<-rpois(20,8)
> df2<-data.frame(y1,y2,y3)
> df2
 y1 y2 y3
1 1 9 14
2 1 4 9
3 0 9 11
4 2 4 8
5 1 8 6
6 3 3 18
7 2 5 6
8 2 6 12
9 2 1 3
10 0 4 9
11 2 3 9
12 1 5 15
13 1 6 8
14 1 9 10
15 2 2 12
16 2 3 15
17 2 5 10
18 4 7 11
19 2 5 13
20 3 8 9
> apply(df2,2,sd)
y1 y2 y3
0.978721 2.408319 3.545197
 Live Demo
> z1<-runif(20,1,2) > z2<-runif(20,1,5) > z3<-runif(20,2,5) > df3<-data.frame(z1,z2,z3) > df3
      z1       z2       z3
1 1.907492 3.422703 2.855133
2 1.762290 3.250390 3.475309
3 1.486333 2.107422 3.444077
4 1.250209 1.904570 3.314925
5 1.359045 4.934230 3.312890
6 1.008594 1.393549 2.558971
7 1.235712 4.518207 4.836347
8 1.106235 1.933838 2.436035
9 1.611034 4.089584 4.336852
10 1.204697 2.887437 4.440150
11 1.214610 2.635393 2.660501
12 1.016492 4.292893 2.949746
13 1.328194 3.139884 2.792373
14 1.269595 2.964845 3.565541
15 1.913872 1.057963 2.609570
16 1.417872 3.571295 3.959480
17 1.690566 2.281527 2.831667
18 1.900013 3.137568 3.226023
19 1.207709 4.816393 4.510174
20 1.461033 1.161574 3.305159
> apply(df3,2,sd)
   z1       z2          z3
0.2907786 1.1771167 0.7123186
Python – Get the object with the max attribute value in a list of objects

04 Jan, 2022
Given a list of objects, the task is to write a Python program to get the object with the max attribute value in a list of objects using Python. 
This task can be achieved by using the max() method and attrgetter operator. It returns a callable object that fetches attr from its operand. If more than one attribute is requested, returns a tuple of attributes. The attribute names can also contain dots.
Syntax:
attrgetter(attr)
To get the job done, define a class and define a __init__() method. Then, initialize the instance variables for example salary and experience. Now, create multiple instances/ Objects for the geeks class and append all the objects into a list. Now pass the list of objects to the max() method with key=attribute, The attribute can be given using the attrgetter operator.
The max() method will return the object with max attribute value.
Example 1: Get the object with max attribute value in a list of objects
Python3
from operator import attrgetter    class geeks:    def __init__(self, experience, salary):        self.experience = experience        self.salary = salary    object1 = geeks(2, 50000)object2 = geeks(3, 60000)object3 = geeks(1, 20000)object4 = geeks(4, 75000)  l = [object4, object3, object2, object1]max_attr = max(l, key=attrgetter('salary'))print(max_attr.salary)
Output:
75000
Example 2: Get the object with a max attribute value in a list of objects
Python3
from operator import attrgetter    class geeks:    def __init__(self, experience, salary):        self.experience = experience        self.salary = salary    object1 = geeks(7, 57050)object2 = geeks(3, 98000)object5 = geeks(6, 45000)object4 = geeks(1, 89000)object3 = geeks(5, 25000)  l = [object4, object3, object5, object2, object1]max_attr = max(l, key=attrgetter('salary'))print(max_attr.salary)
Output:
98000
Picked
Python list-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to set a Responsive Full Background Image Using CSS ?

31 Mar, 2021
The purpose of this article is to set a Responsive Full Background Image Using CSS.
To set a Responsive Full Background Image using CSS we will use the CSS background-size property that has a value auto that tells the browsers to automatically scale the image’s width and height based on the container, to make element centered. And for small-size devices, we will add media queries that decrease the size of the image file to load fast.
Syntax:
background-size: auto; 
Example:
HTML
<!DOCTYPE html><html lang="en">  <head>    <meta charset="UTF-8" />    <meta http-equiv="X-UA-Compatible"           content="IE=edge" />    <meta name="viewport"           content="width=device-width, initial-scale=1.0" />    <style>      body {        /* Add image */        background-image: url("https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210324142236/gfg_complete_logo_2x-min1.png");          /* Make image center */        background-position: center center;          /* Make image fixed */        background-attachment: fixed;          /* Not repeat images */        background-repeat: no-repeat;          /* Set background size auto */        background-size: auto;      }        /* Media query for mobile devices  */      @media only screen and (max-width: 767px) {        body {          background-image: url("https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210324142236/gfg_complete_logo_2x-min1.png");        }      }    </style>  </head>  <body>  </body></html>
Output:
CSS-Properties
CSS-Questions
Picked
CSS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to create a rank variable using mutate function of dplyr package in R?

A rank variable is created to convert a numerical variable into ordinal variable. This is useful for non-parametric analysis because if the distribution of the numerical variable is not normal or there are assumptions of parametric analysis that cannot be followed by the numerical variable then the raw variable values are not analyzed directly. To create a rank variable using mutate function, we can use dense_rank argument.
Consider the below data frame −
set.seed(7)
x1 <-sample(1:5,20,replace=TRUE)
x2 <-rep(c("Winter","Spring","Summer","Rainy"),times=5)
df <-data.frame(x1,x2)
df
x1 x2
1 2 Winter
2 3 Spring
3 4 Summer
4 2 Rainy
5 2 Winter
6 3 Spring
7 3 Summer
8 2 Rainy
9 4 Winter
10 3 Spring
11 4 Summer
12 2 Rainy
13 3 Winter
14 5 Spring
15 4 Summer
16 3 Rainy
17 2 Winter
18 2 Spring
19 4 Summer
20 3 Rainy
library(dplyr)
Creating a rank variable for x1 variable −
df%>%mutate(Rank_x1=dense_rank(desc(-x1)))
x1 x2 Rank_x1
1 2 Winter 1
2 3 Spring 2
3 4 Summer 3
4 2 Rainy 1
5 2 Winter 1
6 3 Spring 2
7 3 Summer 2
8 2 Rainy 1
9 4 Winter 3
10 3 Spring 2
11 4 Summer 3
12 2 Rainy 1
13 3 Winter 2
14 5 Spring 4
15 4 Summer 3
16 3 Rainy 2
17 2 Winter 1
18 2 Spring 1
19 4 Summer 3
20 3 Rainy 2
Let’s have a look at another example −
grp <-rep(c(28,29,31,45,37),times=4)
Percentage <-rep(c(28,29,31,45,37),times=4)
ID <-1:20
df_new <-data.frame(ID,Percentage)
df_new
ID Percentage
1 1 28
2 2 29
3 3 31
4 4 45
5 5 37
6 6 28
7 7 29
8 8 31
9 9 45
10 10 37
11 11 28
12 12 29
13 13 31
14 14 45
15 15 37
16 16 28
17 17 29
18 18 31
19 19 45
20 20 37
df%>%mutate(Rank_Percentage=dense_rank(desc(-Percentage)))
x1 x2 Rank_Percentage
1 2 Winter 1
2 3 Spring 2
3 4 Summer 3
4 2 Rainy 5
5 2 Winter 4
6 3 Spring 1
7 3 Summer 2
8 2 Rainy 3
9 4 Winter 5
10 3 Spring 4
11 4 Summer 1
12 2 Rainy 2
13 3 Winter 3
14 5 Spring 5
15 4 Summer 4
16 3 Rainy 1
17 2 Winter 2
18 2 Spring 3
19 4 Summer 5
20 3 Rainy 4
Python program to find the longest word in a sentence

10 Feb, 2021
Given a string S consisting of lowercase English alphabets, the task is to print the longest word present in the given string in python.
Examples:
Input: S = “be confident and be yourself”Output: “confident”Explanation:Words present in the sentence are “be”, “confident”, “and”, “be” and “yourself”.Length of each of the words are 2, 9, 3, 2, and 8 respectively.Therefore, the longest word is “confident”.
Input: S = “geeks for geeks”Output: “geeks”
Searching-based Approach: Refer to this article to solve this problem by performing the following steps:
Iterate over the characters of the string.
Check if the current character encountered is a space or end of the string is reached.
If the current character is found to be so, update the maximum length of a word obtained.
Finally, print the longest word obtained using substr() method.
Time Complexity: O(N)Auxiliary Space: O(1)
Approach using sorted() method: The idea is to split the string into separate words and store in a list. Then, sort the list in the order of increasing length using the sorted() method. Print the last string in the sorted list.
Below is the implementation of the above approach:
Python3
# Python3 program for the above approach  # Function to print the longest# word in given sentencedef largestWord(s):      # Sort the words in increasing    # order of their lengths    s = sorted(s, key = len)      # Print last word    print(s[-1])    # Driver Codeif __name__ == "__main__":      # Given string    s = "be confident and be yourself"      # Split the string into words    l = list(s.split(" "))      largestWord(l)
confident

Time Complexity: O(N * logN)Auxiliary Space: O(1)
python-list
python-string
Python Programs
Sorting
Strings
Technical Scripter
python-list
Strings
Sorting
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python | Convert string dictionary to dictionary
Python Program for Fibonacci numbers
Python program to add two numbers
Python Program for Binary Search (Recursive and Iterative)
Python Program for factorial of a number
Merge Sort
Bubble Sort Algorithm
QuickSort
Insertion Sort
Selection Sort Algorithm
Scala | Trait App

12 Apr, 2019
App is a trait which is utilized to rapidly change objects into feasible programs, which is carried out by applying DelayedInit function and the objects inheriting the trait App uses this function to execute the entire body of the program as a section of an inherited main method.Note:
trait App extends DelayedInit
The Linear Super-types here are:DelayedInit, AnyRef, Any
DelayedInit, AnyRef, Any
The value members are:val executionStart: Longdef main(args: Array[String]): Unit
val executionStart: Long
def main(args: Array[String]): Unit
Now, lets see some examples.
Example :// Scala program of a trait// App  // Applying the trait Appobject GfG extends App{      // Displays output    println("GeeksforGeeks")  }Output:GeeksforGeeks
Here, the object GfG inherits the main method of App and prints the output, and so we don’t need to create the main method manually.
// Scala program of a trait// App  // Applying the trait Appobject GfG extends App{      // Displays output    println("GeeksforGeeks")  }
GeeksforGeeks

Here, the object GfG inherits the main method of App and prints the output, and so we don’t need to create the main method manually.
Example:// Scala program of trait// Appobject GfG extends App {    // conditions stated    if (args.length == 1)    {          // Displays this as output if         // the command line arguments        // are equal to one        println("Student: ${args(0)}")    }          else    {              // Displays this if no arguments         // are given in the command line        println("There are no students.")    }}Output:There are no students.
Note: Here, args is utilized for command line arguments, which will return the instant command line arguments like an array.The output obtained here is the string stated above in the else part as no command line arguments are provided. If we provide the command line arguments like below then the output will be:// command line argument
$ scala GfG Nidhi 

// Output
Student: Nidhi
Here, one argument is given so only that is returned.
// Scala program of trait// Appobject GfG extends App {    // conditions stated    if (args.length == 1)    {          // Displays this as output if         // the command line arguments        // are equal to one        println("Student: ${args(0)}")    }          else    {              // Displays this if no arguments         // are given in the command line        println("There are no students.")    }}
There are no students.

Note: Here, args is utilized for command line arguments, which will return the instant command line arguments like an array.The output obtained here is the string stated above in the else part as no command line arguments are provided. If we provide the command line arguments like below then the output will be:
// command line argument
$ scala GfG Nidhi 

// Output
Student: Nidhi

Here, one argument is given so only that is returned.
Scala
scala-traits
Scala
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python | Detect Polygons in an Image using OpenCV

13 Oct, 2019
Approach : The approach we would be used to detect the shape of a given polygon will be based on classifying the detected shape on the basis of a number of sides it has. For example, if the detected polynomial has 3 sides, then it could be considered as a triangle, if the polynomial has 4 sides then it could be classified as a square or a rectangle.
Prerequisite :
Make sure you have Python3, OpenCV, numpy already installed on your computer.
Basic knowledge about OpenCV would be helpful – Basics of OpenCV
Make sure to save the image in which shapes is to be detected in your local directory
Implementation : In the following code, we will be detecting an arrow-shaped object from the image ‘arrow.jpg’. The shape will be detected on the basis of the number of sides it has
Code: Python program to detect polygons in an image
# Python code to detect an arrow (seven-sided shape) from an image.import numpy as npimport cv2   # Reading imageimg2 = cv2.imread('arrow.jpg', cv2.IMREAD_COLOR)   # Reading same image in another variable and # converting to gray scale.img = cv2.imread('arrow.jpg', cv2.IMREAD_GRAYSCALE)   # Converting image to a binary image # (black and white only image)._,threshold = cv2.threshold(img, 110, 255,                             cv2.THRESH_BINARY)   # Detecting shapes in image by selecting region # with same colors or intensity.contours,_=cv2.findContours(threshold, cv2.RETR_TREE,                            cv2.CHAIN_APPROX_SIMPLE)   # Searching through every region selected to # find the required polygon.for cnt in contours :    area = cv2.contourArea(cnt)       # Shortlisting the regions based on there area.    if area > 400:         approx = cv2.approxPolyDP(cnt,                                   0.009 * cv2.arcLength(cnt, True), True)           # Checking if the no. of sides of the selected region is 7.        if(len(approx) == 7):             cv2.drawContours(img2, [approx], 0, (0, 0, 255), 5)   # Showing the image along with outlined arrow.cv2.imshow('image2', img2)    # Exiting the window if 'q' is pressed on the keyboard.if cv2.waitKey(0) & 0xFF == ord('q'):     cv2.destroyAllWindows()
Note : The parameter ‘110’ in threshold could be adjusted as per need if the object is of different colour and is based on trial and error.
Result :
Image with arrow
Binary Image
Outlined Arrow
Image-Processing
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
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Python Classes and Objects
Python OOPs Concepts
Introduction To PYTHON
Convert integer to string in Python
Maximum value in record list as tuple attribute in Python

When it is required to find the maximum value in a record list of tuples, the list comprehension and the 'max' methods can be used.
A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).
A list of tuple basically contains tuples enclosed in a list. The list comprehension is a shorthand to iterate through the list and perform operations on it.
The 'max' method can be used to find the maximum of all the elements in an iterable.
Below is a demonstration of the same −
Live Demo
my_list = [('Will', [67, 45, 89]), ('Jam', [34, 56,13]), ('Pow', [99, 123, 89]), ('Nyk', [0, 56, 5])]

print ("The list of tuples is : " )
print(my_list)

my_result = [(key, max(lst)) for key, lst in my_list]

print ("The maximum of list tuple attribute is : " )
print(my_result)
The list of tuples is :
[('Will', [67, 45, 89]), ('Jam', [34, 56, 13]), ('Pow', [99, 123, 89]), ('Nyk', [0, 56, 5])]
The maximum of list tuple attribute is :
[('Will', 89), ('Jam', 56), ('Pow', 123), ('Nyk', 56)]
A list of tuples is defined, and is displayed on the console.
The list comprehension is used to iterate through the list, and the maximum of the values in the tuple (inside the list of tuple) is obtained.
This operation's result is assigned to a variable.
It is then displayed on the console as the output.
How can I update the boolean values in MySQL?

You can update boolean value using UPDATE command. If you use the BOOLEAN data type, MySQL internally convert it into tinyint(1). It can takes true or false literal in which true indicates 1 to tinyint(1) and false indicates 0 to tinyint(1).
The syntax is as follows −
UPDATE yourTableName SET yourColumnName = yourValue WHERE yourCondition;
To understand the above syntax, let us create a table. The query to create a table is as follows −
mysql> create table UpdateBooleans
   -> (
   -> Id int NOT NULL AUTO_INCREMENT,
   -> isSuccessful BOOLEAN,
   -> PRIMARY KEY(Id)
   -> );
Query OK, 0 rows affected (1.55 sec)
Insert some records in the table using insert command. The query is as follows −
mysql> insert into UpdateBooleans(isSuccessful) values(true);
Query OK, 1 row affected (0.17 sec)

mysql> insert into UpdateBooleans(isSuccessful) values(false);
Query OK, 1 row affected (0.21 sec)

mysql> insert into UpdateBooleans(isSuccessful) values(true);
Query OK, 1 row affected (0.13 sec)

mysql> insert into UpdateBooleans(isSuccessful) values(false);
Query OK, 1 row affected (0.15 sec)

mysql> insert into UpdateBooleans(isSuccessful) values(false);
Query OK, 1 row affected (0.24 sec)

mysql> insert into UpdateBooleans(isSuccessful) values(false);
Query OK, 1 row affected (0.17 sec)

mysql> insert into UpdateBooleans(isSuccessful) values(true);
Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from UpdateBooleans;
The following is the output −
+----+--------------+
| Id | isSuccessful |
+----+--------------+
| 1  | 1            |
| 2  | 0            |
| 3  | 1            |
| 4  | 0            |
| 5  | 0            |
| 6  | 0            |
| 7  | 1            |
+----+--------------+
7 rows in set (0.00 sec)
Here is the query to update boolean values. Let us update all 0s to 1:
mysql> update UpdateBooleans set isSuccessful = true where isSuccessful = false;
Query OK, 4 rows affected (0.15 sec)
Rows matched: 4 Changed: 4 Warnings: 0
Display the records from the table once again. The query is as follows:
mysql> select *from UpdateBooleans;
The following is the output:
+----+--------------+
| Id | isSuccessful |
+----+--------------+
| 1  | 1            |
| 2  | 1            |
| 3  | 1            |
| 4  | 1            |
| 5  | 1            |            
| 6  | 1            |
| 7  | 1            |
+----+--------------+
7 rows in set (0.00 sec)
Reflection In 2D Graphics

12 Oct, 2020
Reflection deals with obtaining a mirror image of the 2D object. 
About x-axis: If P(x, y) is the point on x-y plane then P’(x’, y’) is the reflection about x-axis given as x’=x ; y’=-y 
 
Matrix Form: 
 
About y-axis : If P(x, y) is the point on x-y plane then P’(x’, y’) is the reflection about y-axis given as x’=-x ; y’=y 
 
 
Along origin : If P(x, y) is the point on x-y plane then P’(x’, y’) is the reflection about origin given as x’=-x ; y’=-y 
 
 
About x=y line : To do this move x=y line to any of the axis. In the given diagram the angle of rotation is 45o as the points are plotted as (0, 0), (1, 1), (2, 2), and so on. 
 
Imposing the line clockwise (-45o) imposing it on the x-axis we have,  
We know,  
and  
 
Now perform reflection along x-axis,  
Now rotate the line back 45o in an anticlockwise direction,  
Now if P(x, y) is the point on x-y plane then P’(x’, y’) is the reflection about x=y line given as x’=y ; y’=x  Matrix Form:  
Problem: A triangle is given with the coordinates p (5 4), q (2 2), r (5 6) we need to reflect it along Y-axis.
Ans: We are given with coordinate p, q, r as shown in figure-
Triangle reflection in 2-d graphics
Now, we apply the condition of reflecting a 2-d object along Y-axis:
First coordinate p, becomes p’ after reflection:
Second coordinate q, becomes q’ after reflection:
Third coordinate r of the triangle becomes r’ after reflection:
After reflecting the triangle about the Y-axis point p, q, r becomes p’, q’, r’ :
p(5, 4) = p'(-5, 4) , q(2, 2) 
= q'(-2, 2) , r(5, 6) 
= r'(-5, 6) 
The reflecting object would appear as :
madhav_mohan
computer-graphics
Misc
Misc
Misc
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Hypervisor
Advantages and Disadvantages of OOP
Introduction to Electronic Mail
Cloud Computing
Analog to Digital Conversion
array::size() in C++ STL
Characteristics of Cloud Computing
Bubble Sort algorithm using JavaScript
Introduction to Deep Learning
Types of Cloud