code-rag-bench/online-tutorials huggingface dataset:
Python | Check if variable is tuple - GeeksforGeeks

21 Nov, 2019
Sometimes, while working with Python, we can have a problem in which we need to check if a variable is single or a record. This has applications in domains in which we need to restrict the type of data we work on. Let’s discuss certain ways in which this task can be performed.
Method #1 : Using type()This inbuilt function can be used as shorthand to perform this task. It checks for the type of variable and can be employed to check tuple as well.
# Python3 code to demonstrate working of# Check if variable is tuple# using type()  # initialize tuple test_tup = (4, 5, 6)  # printing original tupleprint("The original tuple : " + str(test_tup))  # Check if variable is tuple# using type()res = type(test_tup) is tuple  # printing resultprint("Is variable tuple ? : " + str(res))
The original tuple : (4, 5, 6)
Is variable tuple ? : True

 
Method #2 : Using isinstance()Yet another function that can be employed to perform this task. It also returns true, in case the parent class of variable(if exists) is a tuple.
# Python3 code to demonstrate working of# Check if variable is tuple# using isinstance()  # initialize tuple test_tup = (4, 5, 6)  # printing original tupleprint("The original tuple : " + str(test_tup))  # Check if variable is tuple# using isinstance()res = isinstance(test_tup, tuple)   # printing resultprint("Is variable tuple ? : " + str(res))
The original tuple : (4, 5, 6)
Is variable tuple ? : True

Python tuple-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Read a file line by line in Python
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
Python program to convert a list to string
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Split string into list of characters
Python | Convert a list to dictionary
C library function - mbstowcs()

The C library function size_t mbstowcs(schar_t *pwcs, const char *str, size_t n) converts the string of multi-byte characters pointed to, by the argument str to the array pointed to by pwcs.
Following is the declaration for mbstowcs() function.
size_t mbstowcs(schar_t *pwcs, const char *str, size_t n)
pwcs − This is the pointer to an array of wchar_t elements that is long enough to store a wide string max characters long.
pwcs − This is the pointer to an array of wchar_t elements that is long enough to store a wide string max characters long.
str − This is the C multi-byte character string to be interpreted.
str − This is the C multi-byte character string to be interpreted.
n − This is the maximum number of wchar_t characters to be interpreted.
n − This is the maximum number of wchar_t characters to be interpreted.
This function returns the number of characters translated, excluding the ending null-character. If an invalid multi-byte character is encountered, a -1 value is returned.
The following example shows the usage of mbstowcs() function.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main () {
   int len;
   char *pmbnull  = NULL;
   char *pmb = (char *)malloc( MB_CUR_MAX );
   wchar_t *pwc = L"Hi";
   wchar_t *pwcs = (wchar_t *)malloc( sizeof( wchar_t ));

   printf("Converting to multibyte string\n");
   len = wcstombs( pmb, pwc, MB_CUR_MAX);
   printf("Characters converted %d\n", len);
   printf("Hex value of first multibyte character: %#.4x\n", pmb);
   
   printf("Converting back to Wide-Character string\n");
   len = mbstowcs( pwcs, pmb, MB_CUR_MAX);
   printf("Characters converted %d\n", len);
   printf("Hex value of first wide character %#.4x\n\n", pwcs);
   
   return(0);
}
Let us compile and run the above program that will produce the following result −
Converting to multibyte string
Characters converted 1
Hex value of first multibyte character: 0x19a60010
Converting back to Wide-Character string
Characters converted 1
Hex value of first wide character 0x19a60030


    12 Lectures 
     2 hours 

 Nishant Malik

    12 Lectures 
     2.5 hours 

 Nishant Malik

    48 Lectures 
     6.5 hours 

 Asif Hussain

    12 Lectures 
     2 hours 

 Richa Maheshwari

    20 Lectures 
     3.5 hours 

 Vandana Annavaram

    44 Lectures 
     1 hours 

 Amit Diwan
 Print
 Add Notes
 Bookmark this page
Clojure - Recursion

We have seen the recur statement in an earlier topic and whereas the ‘for’ loop is somewhat like a loop, recur is a real loop in Clojure.
If you have a programming background, you may have heard of tail recursion, which is a major feature of functional languages. This recur special form is the one that implements tail recursion. As the word “tail recursion” indicates, recur must be called in the tail position. In other words, recur must be the last thing to be evaluated.
The simplest example of the recur statement is used within the ‘for’ loop. In the following example, the recur statement is used to change the value of the variable ‘i’ and feed the value of the variable back to the loop expression.
(ns clojure.examples.hello
   (:gen-class))

;; This program displays Hello World
(defn Example []
   (loop [i 0]
      (when (< i 5)
      (println i)
      (recur (inc i)))))
(Example)
The above program produces the following output.
0
1
2
3
4

 Print
 Add Notes
 Bookmark this page
Check if a value is present in an Array in Java

At first sort the array −
int intArr[] = {55, 20, 10, 60, 12, 90, 59};
// sorting array
Arrays.sort(intArr);
Now, set the value to be searched in an int variable −
int searchVal = 12;
Check for the presence of a value in an array −
int retVal = Arrays.binarySearch(intArr,searchVal);
boolean res = retVal > 0 ? true : false;
Following is an example to check if a value is present in an array −
import java.util.Arrays;
public class Main {
   public static void main(String[] args) {
      // initializing unsorted int array
      int intArr[] = {55, 20, 10, 60, 12, 90, 59};
      // sorting array
      Arrays.sort(intArr);
      // let us print all the elements available in list
      System.out.println("The sorted int array is:");
      for (int number : intArr) {
         System.out.println("Number = " + number);
      }
      // entering the value to be searched
      int searchVal = 12;
      int retVal = Arrays.binarySearch(intArr,searchVal);
      boolean res = retVal > 0 ? true : false;
      System.out.println("Is element 12 in the array? = " + res);
      System.out.println("The index of element 12 is : " + retVal);
   }
}
The sorted int array is:
Number = 10
Number = 12
Number = 20
Number = 55
Number = 59
Number = 60
Number = 90
Is element 12 in the array? = true
The index of element 12 is : 1
Function prototypes in JavaScript

Functions created in JavaScript always have the prototype property added by the JavaScript
engine to them. The prototype property is an object which contains the constructor property
by default. The function protoype can be accessed by −
functionName.prototype
When objects are creating using the function constructor, this prototype property can be used to share methods or properties between the objects created by that function constructor.
Following is the code for function prototypes in JavaScript −
 Live Demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   }
   .result {
      font-size: 20px;
      font-weight: 500;
      color: blueviolet;
   }
</style>
</head>
<body>
<h1>Function prototypes in JavaScript</h1>
<div class="result"></div>
<br />
<button class="Btn">Click Here</button>
<h3>Click on the above button to call the welcome method of person1 and person2 object</h3>
<script>
   let resEle = document.querySelector(".result");
   let BtnEle = document.querySelector(".Btn");
   function personConstructor(fName, lName) {
      this.fName = fName;
      this.lName = lName;
   }
   personConstructor.prototype.welcome = function () {
      return "Welcome " + this.fName + " " + this.lName;
   };
   let person1 = new personConstructor("Rohan", "Sharma");
   let person2 = new personConstructor("Shawn", "Smith");
   BtnEle.addEventListener("click", () => {
      resEle.innerHTML = "person1.welcome() = " + person1.welcome() + "<br>";
      resEle.innerHTML += "person2.welcome() = " + person2.welcome() + "<br>";
   });
</script>
</body>
</html>
On clicking the ‘Click Here’ button −
CICS - WRITE

Write command is used to add new records to a file. The parameters used in Write command are same as we had described before. Data is picked from the data area mentioned in the FROM clause. Following is the syntax for Write command −
EXEC CICS WRITE
   FILE(name)
   FROM(data-area)
   RIDFLD(data-area)
   LENGTH(data-value)
   KEYLENGTH(data-value)
END-EXEC.

Following is the example to write a record in 'FL001' file where Student-id is the primary key and a new record with 101 student id will be written in the file −
IDENTIFICATION DIVISION.                                         
PROGRAM-ID. HELLO.                                               
DATA DIVISION. 
WORKING-STORAGE SECTION.
01 WS-STD-REC-LEN    PIC S9(4) COMP.
01 WS-STD-KEY-LEN    PIC S9(4) COMP.
01 WS-STD-REC-KEY    PIC 9(3).
01 WS-STD-REC        PIC X(70).
PROCEDURE DIVISION.
MOVE +70           TO WS-STD-REC-LEN.
MOVE ‘101’         TO WS-STD-REC-KEY.
MOVE 3             TO WS-STD-KEY-LEN.
MOVE '101Mohtahim M TutorialsPoint' TO WS-STD-REC.
EXEC CICS WRITE
   FILE ('FL001')
   FROM (WS-STD-REC)
   LENGTH (WS-STD-REC-LEN)
   RIDFLD (WS-STD-REC-KEY)
   KEYLENGTH (WS-STD-KEY-LEN)
END-EXEC.
The following table shows the list of exceptions that arise during a WRITE statement −
NOTOPEN
File is not open.
FILENOTFOUND
File entry is not made in FCT.
LENGERR
Mismatch between the length specified in command and actual length of the record.
NOTAUTH
If the user does not have enough permissions to use the file.
DUPKEY
If more than 1 record satisfy the condition on the alternate key.
NOSPACE
There is not enough space in the dataset.
 Print
 Add Notes
 Bookmark this page
Faster Levenshtein Distance Calculation using mbleven | by Parthvi Shah | Towards Data Science

Levenshtein Distance is the minimal number of insertions, deletions, and symbol substitutions required to transform a string a into string b.
Example: Consider string a: mouse & string b: morse
Levenshtein distance between string a and string b is 2. You need to delete u from string a and insert r to transform string a to string b.
There is also one other modification to levenshtein distance:
Damerau Levenshtein follows exactly the same approach as Levenshtein Distance but you can also use transpositions (swapping of adjacent symbols) and hence, it makes levenshtein faster and efficient.
Damerau Levenshtein follows exactly the same approach as Levenshtein Distance but you can also use transpositions (swapping of adjacent symbols) and hence, it makes levenshtein faster and efficient.
In the above example, Damerau-Levenshtein distance between string a and string b is 1. You just need to substitute u from string a with r to transform string a to string b.
As easy as it seems, Levenshtein Distance takes a lot of time to run if you have thousands of rows in a pandas DataFrame.
Unlike Levenshtein, mbleven is a “hypotheses-based algorithm”. It will first list down all the possible hypotheses to transform one string to the other.
Possible hypotheses for the example mentioned above:
Can string a be converted to string b if I insert r?Can string a be converted to string b if I delete u?Can string a be converted to string b if I substitute u?....
Can string a be converted to string b if I insert r?
Can string a be converted to string b if I delete u?
Can string a be converted to string b if I substitute u?
....
mbleven will check out all the hypotheses one by one. All the hypotheses can be computed in O(n) times.
The entire code and its implementation can be viewed here: https://github.com/fujimotos/mbleven
mbleven can confirm if one string can be converted to the other string using the mentioned k-bound & it can also return the edit-distance between the two strings. A few of the examples mentioned are:
>>> from mbleven import compare>>> compare("meet", "meat")1>>> compare("meet", "eat")2>>> compare("meet", "mars")  # distance 3-1
The last example returns -1 because the distance between these two strings is 3 edit-distance and this algorithm has an upper bound of 2 edit-distance by default.
Vue.js | v-on:click directive

22 Jun, 2020
The v-on:click directive is a Vue.js directive used to add a click event listener to an element. First, we will create a div element with id as app and let’s apply the v-on:click directive to a element. Further, we can execute a function when click even occurs.
Syntax:
v-on:click="function"

Parameters: This directive accepts function which will be executed when the click event occurs.Example: This example uses VueJS to toggle the visibility of a element with v-on:click.
HTML
<!DOCTYPE html><html>  <head>    <title>        VueJS | v-on:click directive    </title>      <!-- Load Vuejs -->    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js">    </script></head>  <body>    <div style="text-align: center;width: 600px;">        <h1 style="color: green;">            GeeksforGeeks        </h1>        <b>            VueJS | v-on:click directive        </b>    </div>      <div id="canvas" style="border:1px solid #000000;                            width: 600px;height: 200px;">        <div id="app" style="text-align: center;                             padding-top: 40px;">            <button v-on:click="data = !data">              Show            </button>            <h1 v-if="data">GeeksforGeeks</h1>        </div>    </div>      <script>        var app = new Vue({            el: '#app',            data: {                data: false            }        })    </script></body></html>
Output:
Vue.JS
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
Remove elements from a JavaScript Array
How to append HTML code to a div using JavaScript ?
Difference Between PUT and PATCH Request
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Installation of Node.js on Linux
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?
Overview of testing package in Golang

18 Dec, 2021
In the software industry, there are clear differences between manual testing and automated testing. Where manual testing is used to ensure that the software code performs as expected and it requires time and effort. Most of the manual testing includes checking log files, external services, and the database for errors. In a dissimilar fashion, Automated testing is, well, automated where certain software/code perform the testing as the user would do. Because automated testing is done using an automation tool, exploration tests take less time and more test scripts, while increasing the overall scope of the tests.
In Golang, package testing is responsible for different types of testing maybe it is performance testing, parallel testing, functional testing, or any possible combination of these all.
The testing package provides support for automated testing of the Golang code. To run any test function use “go test” command, which automates the execution of any function of the form  TestXxx(*testing.T), where Xxx must not start with any lowercase letter.
Test Function Syntax :
func TestXxx(*testing.T)
Steps for writing test suite in Golang:
Create a file whose name ends with _test.go
Import package testing by import “testing” command
Write the test function of form func TestXxx(*testing.T) which uses any of Error, Fail, or related methods to signal failure.
Put the file in any package.
Run command go test
Note: test file will be excluded in package build and will only get executed on go test command.
Example:
File: main.go 
Go
package main // function which return "geeks"func ReturnGeeks() string{    return "geeks";} // main function of packagefunc main() {    ReturnGeeks()}
  
Test file: pkg_test.go
 
Go
package main import (    "testing") // test functionfunc TestReturnGeeks(t *testing.T) {    actualString := ReturnGeeks()    expectedString := "geeks"    if actualString != expectedString{        t.Errorf("Expected String(%s) is not same as"+         " actual string (%s)", expectedString,actualString)    }}
Output:
Screen after running test case
amshashank
Golang-Packages
Go Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
strings.Replace() Function in Golang With Examples
fmt.Sprintf() Function in Golang With Examples
Arrays in Go
Golang Maps
How to Split a String in Golang?
Interfaces in Golang
Data Types in Go
Slices in Golang
Different Ways to Find the Type of Variable in Golang
How to Parse JSON in Golang?
Memory Management in Operating Systems - GeeksQuiz

03 Oct, 2019
Let the page size is of 'x' bits

Size of T1 = 2 ^ x bytes

(This is because T1 occupies exactly one page)

Now, number of entries in T1 = (2^x) / 4

(This is because each page table entry is 32 bits
  or 4 bytes in size)

Number of entries in T1 = Number of second level 
page tables

(Because each I-level page table entry stores the 
 base address of page of II-level page table)

Total size of second level page tables = ((2^x) / 4) * (2^x)

Similarly, number of entries in II-level page tables = Number
 of III level page tables = ((2^x) / 4) * ((2^x) / 4)

Total size of third level page tables = ((2^x) / 4) * 
                                        ((2^x) / 4) * (2^x)

Similarly, total number of entries (pages) in all III-level 
page tables = ((2^x) / 4) * ((2^x) / 4) * ((2^x) / 4)
            = 2^(3x - 6)

Size of virtual memory = 2^46

Number of pages in virtual memory = (2^46) / (2^x) = 2^(46 - x)

Total number the pages in the III-level page tables = 
                              Number of pages in virtual memory

2^(3x - 6) = 2^(46 - x)

3x - 6 = 46 - x

4x = 52
x = 13

That means, page size is of 13 bits
or Page size = 2^13 bytes = 8 KB 
1 MB 16-way set associative virtually indexed physically tagged cache(VIPT). 
The cache block size is 64 bytes.

No of blocks is 2^20/2^6 = 2^14.

No of sets is 2^14/2^4 = 2^10.

VA(46)
+-------------------------------+
tag(30) , Set(10) , block offset(6)
+-------------------------------+

In VIPT if the no. of bits of page offset = 
                  (Set+block offset) then only one page color is sufficient.

but we need 8 colors because the number bits where the cache set index and 
physical page number over lap is 3 so 2^3 page colors is required.(option 
c is ans). 
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
PostgreSQL – While Loops

24 Jan, 2021
PostgreSQL provides the loop statement which simply defines an unconditional loop that executes repeatedly a block of code until terminated by an exit or return statement. The while loop statement executes a block of code till the condition remains true and stops executing when the conditions become false.
The syntax of the loop statement:
[ <<label>> ]
while condition loop
  statements;
end loop;
If we analyze the above syntax:
Condition: If the condition is true, it executes the statements. After each iteration, the while loop again checks the condition.
Body / Statements: Inside the body of the while loop, we need to change the values of some variables to make the condition false or null at some points. Otherwise, we will encounter the case of an infinite loop.
As the while loop tests the condition before executing the statements, it is also referred to as a pretest loop.
The following flowchart describes the while loop statement:
Flowchart of While loop
Example 1:
 The following code is used to raise notices while increasing the count of an arbitrary variable from 0 to 9.
do $$
declare
add integer := 0;
begin
while add <10 loop
raise notice 'Out addition count %', add;
add := add+1;
end loop;
end$$;
Output:
Example 2:
 The following code is used to raise notices while decreasing the count of an arbitrary variable from 10 to 1.
do $$
declare
add integer := 10;
begin
while add > 0 loop
raise notice 'Out addition count %',add;
add := add-1;
end loop;
end$$;
Output:
Picked
Technical Scripter 2020
PostgreSQL
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
PostgreSQL - Psql commands
PostgreSQL - Change Column Type
PostgreSQL - For Loops
PostgreSQL - Function Returning A Table
PostgreSQL - LIMIT with OFFSET clause
PostgreSQL - ARRAY_AGG() Function
PostgreSQL - DROP INDEX
PostgreSQL - Create Auto-increment Column using SERIAL
PostgreSQL - Copy Table
PostgreSQL - ROW_NUMBER Function
Deadlock - GeeksforGeeks

28 Mar, 2020
 if (i % 2 == 0) {
      if (i < n) request Ri
      if (i+2 < n) request Ri+2
}
else {
      if (i < n) request Rn-i
      if (i+2 < n) request Rn-i-2
}
Option B is answer

No. of resources, n = 21
No. of processes, k = 12

Processes {P0, P1....P11}  make the following Resource requests:
{R0, R20, R2, R18, R4, R16, R6, R14, R8, R12, R10, R10}

For example P0 will request R0 (0%2 is = 0 and 0< n=21). 

Similarly, P10 will request R10.

P11 will request R10 as n - i = 21 - 11 = 10.

As different processes are requesting the same resource, deadlock
may occur. 
Process P1: 
t=0: requests 2 units of R2 
t=1: requests 1 unit of R3 
t=3: requests 2 units of R1 
t=5: releases 1 unit of R2    
        and 1 unit of R1. 
t=7: releases 1 unit of R3 
t=8: requests 2 units of R4 
t=10: Finishes

Process P2: 
t=0: requests 2 units of R3 
t=2: requests 1 unit of R4 
t=4: requests 1 unit of R1 
t=6: releases 1 unit of R3 
t=8: Finishes

Process P3: 
t=0: requests 1 unit of R4 
t=2: requests 2 units of R1 
t=5: releases 2 units of R1 
t=7: requests 1 unit of R2 
t=8: requests 1 unit of R3 
t=9: Finishes
We can apply the following Deadlock Detection algorithm and see that there is no process waiting indefinitely for a resource. See this for deadlock detection algorithm.
REQ1: P0 requests 0 units of X,  
      0 units of Y and 2 units of Z
REQ2: P1 requests 2 units of X, 
      0 units of Y and 0 units of Z
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, ...
Must Do Coding Questions for Product Based Companies
50 Common Ports You Should Know
GeeksforGeeks Jobathon - Are You Ready For This Hiring Challenge?
Types of Distributed System
Spring Boot - Thymeleaf with Example
Naming Convention in C++
How to Install MySQL on Linux?
Floyd’s Cycle Finding Algorithm
How to use arrays to swap variables in JavaScript ?
How to perform tukey HSD in base R?

First thing you must remember while moving on to post hoc analysis is the null hypothesis of the analysis of variance must be rejected, so that we can claim there exists a difference in the group means. Now, once we achieve that the tukey HSD can be performed simply by using TukeyHSD function in base R.
Consider the below data frame −
 Live Demo
x1<-rep(LETTERS[1:4],5)
y1<-rep(c(5,2000,30,99),5)
df1<-data.frame(x1,y1)
df1
  x1 y1
1  A 5
2  B 2000
3  C 30
4  D 99
5  A 5
6  B 2000
7  C 30
8  D 99
9  A 5
10 B 2000
11 C 30
12 D 99
13 A 5
14 B 2000
15 C 30
16 D 99
17 A 5
18 B 2000
19 C 30
20 D 99
Performing analysis of variance −
ANOVA<-aov(y1~x1,data=df1)
summary(ANOVA)
Df Sum Sq Mean Sq F value Pr(>F)
x1 3 14361185 4787062 1.07e+32 <2e-16 ***
Residuals 16 0 0
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Performing tukey HSD −
TukeyHSD(ANOVA)
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = y1 ~ x1, data = df1)
$x1
diff lwr upr p adj
B-A 1995 1995 1995 0
C-A 25 25 25 0
D-A 94 94 94 0
C-B -1970 -1970 -1970 0
D-B -1901 -1901 -1901 0
D-C 69 69 69 0
Consider the PlantGrowth data in base R −
 Live Demo
str(PlantGrowth)
'data.frame': 30 obs. of 2 variables:
$ weight: num 4.17 5.58 5.18 6.11 4.5 4.61 5.17 4.53 5.33 5.14 ...
$ group : Factor w/ 3 levels "ctrl","trt1",..: 1 1 1 1 1 1 1 1 1 1 ...
 Live Demo
head(PlantGrowth,20)
 weight group
1 4.17 ctrl
2 5.58 ctrl
3 5.18 ctrl
4 6.11 ctrl
5 4.50 ctrl
6 4.61 ctrl
7 5.17 ctrl
8 4.53 ctrl
9 5.33 ctrl
10 5.14 ctrl
11 4.81 trt1
12 4.17 trt1
13 4.41 trt1
14 3.59 trt1
15 5.87 trt1
16 3.83 trt1
17 6.03 trt1
18 4.89 trt1
19 4.32 trt1
20 4.69 trt1
Performing analysis of variance −
 Live Demo
ANOVA<-aov(weight~group,data=PlantGrowth)
summary(ANOVA)
Df Sum Sq Mean Sq F value Pr(>F)
group 2 3.766 1.8832 4.846 0.0159 *
Residuals 27 10.492 0.3886
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Performing tukey HSD −
TukeyHSD(ANOVA)
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = weight ~ group, data = PlantGrowth)
$group
diff lwr upr p adj
trt1-ctrl -0.371 -1.0622161 0.3202161 0.3908711
trt2-ctrl 0.494 -0.1972161 1.1852161 0.1979960
trt2-trt1 0.865 0.1737839 1.5562161 0.0120064
Python | sympy.Derivative() method

02 Aug, 2019
With the help of sympy.Derivative() method, we can create an unevaluated derivative of a SymPy expression. It has the same syntax as diff() method. To evaluate an unevaluated derivative, use the doit() method.
Syntax: Derivative(expression, reference variable)
Parameters:expression – A SymPy expression whose unevaluated derivative is found.reference variable – Variable with respect to which derivative is found.
Returns: Returns an unevaluated derivative of the given expression.
Example #1:
# import sympy from sympy import *   x, y = symbols('x y')expr = x**2 + 2 * y + y**3print("Expression : {} ".format(expr))   # Use sympy.Derivative() method expr_diff = Derivative(expr, x)        print("Derivative of expression with respect to x : {}".format(expr_diff))  print("Value of the derivative : {} ".format(expr_diff.doit()))
Output:
Expression : x**2 + y**3 + 2*y 
Derivative of expression with respect to x : Derivative(x**2 + y**3 + 2*y, x)
Value of the derivative : 2*x 

Example #2:
# import sympy from sympy import *   x, y = symbols('x y')expr = y**2 * x**2 + 2 * y*x + x**3 * y**3print("Expression : {} ".format(expr))   # Use sympy.Derivative() method expr_diff = Derivative(expr, x, y)        print("Derivative of expression with respect to x : {}".format(expr_diff))  print("Value of the derivative : {} ".format(expr_diff.doit()))
Output:
Expression : x**3*y**3 + x**2*y**2 + 2*x*y 
Derivative of expression with respect to x : Derivative(x**3*y**3 + x**2*y**2 + 2*x*y, x, y)
Value of the derivative : 9*x**2*y**2 + 4*x*y + 2 

SymPy
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
How to remove all non-alphanumeric characters from a string in Java

11 Jul, 2020
Given a string str, the task is to remove all non-alphanumeric characters from it and print the modified it. Examples: 
Input: @!Geeks-for’Geeks,123 Output: GeeksforGeeks123 Explanation: at symbol(@), exclamation point(!), dash(-), apostrophes(‘), and commas(, ) are removed.
Input: Geeks_for$ Geeks?{}[] Output: GeeksforGeeks Explanation: underscore(_), dollar sign($), white space, question mark(?), curly braces({}), and square bracket([]) are removed.
Input: GeeksforGeeks123 Output: GeeksforGeeks123 Explanation: No need to remove any character, because the given string doesn’t have any non-alphanumeric character.
Method 1: Using ASCII valuesSince the alphanumeric characters lie in the ASCII value range of [65, 90] for uppercase alphabets, [97, 122] for lowercase alphabets, and [48, 57] for digits. Hence traverse the string character by character and fetch the ASCII value of each character. If the ASCII value is not in the above three ranges, then the character is a non-alphanumeric character. Therefore skip such characters and add the rest in another string and print it.
 Method 2: Using String.replaceAll() Non-alphanumeric characters comprise of all the characters except alphabets and numbers. It can be punctuation characters like exclamation mark(!), at symbol(@), commas(, ), question mark(?), colon(:), dash(-) etc and special characters like dollar sign($), equal symbol(=), plus sign(+), apostrophes(‘). 
The approach is to use the String.replaceAll method to replace all the non-alphanumeric characters with an empty string.
Below is the implementation of the above approach: 
Java
// Java program to remove non-alphanumeric// characters from a stringclass GFG {      // Function to remove non-alphanumeric    // characters from string    public static String      removeNonAlphanumeric(String str)    {        // replace the given string        // with empty string        // except the pattern "[^a-zA-Z0-9]"        str = str.replaceAll(          "[^a-zA-Z0-9]", "");          // return string        return str;    }      // Driver Code    public static void main(String args[])    {          // Test Case 1:        String str1           = "@!Geeks-for'Geeks, 123";        System.out.println(          removeNonAlphanumeric(str1));          // Test Case 2:        String str2           = "Geeks_for$ Geeks?{}[]";        System.out.println(          removeNonAlphanumeric(str2));          // Test Case 3:        String str3           = "GeeksforGeeks123";        System.out.println(          removeNonAlphanumeric(str3));    }}
GeeksforGeeks123
GeeksforGeeks
GeeksforGeeks123

Method 3: Using Regular ExpressionAnother approach involved using of regular expression. The string can be easily filtered using the ReGex [^a-zA-Z0-9 ]. 
ASCII
java-regular-expression
Java-String-Programs
Java Programs
School Programming
Strings
Strings
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Teradata - Secondary Index

A table can contain only one primary index. More often, you will come across scenarios where the table contains other columns, using which the data is frequently accessed. Teradata will perform full table scan for those queries. Secondary indexes resolve this issue.
Secondary indexes are an alternate path to access the data. There are some differences between the primary index and the secondary index.
Secondary index is not involved in data distribution.
Secondary index is not involved in data distribution.
Secondary index values are stored in sub tables. These tables are built in all AMPs.
Secondary index values are stored in sub tables. These tables are built in all AMPs.
Secondary indexes are optional.
Secondary indexes are optional.
They can be created during table creation or after a table is created.
They can be created during table creation or after a table is created.
They occupy additional space since they build sub-table and they also require maintenance since the sub-tables need to be updated for each new row.
They occupy additional space since they build sub-table and they also require maintenance since the sub-tables need to be updated for each new row.
There are two types of secondary indexes −
Unique Secondary Index (USI)
Non-Unique Secondary Index (NUSI)
A Unique Secondary Index allows only unique values for the columns defined as USI. Accessing the row by USI is a two amp operation.
The following example creates USI on EmployeeNo column of employee table.
CREATE UNIQUE INDEX(EmployeeNo) on employee;

A Non-Unique Secondary Index allows duplicate values for the columns defined as NUSI. Accessing the row by NUSI is all-amp operation.
The following example creates NUSI on FirstName column of employee table.
CREATE INDEX(FirstName) on Employee;

 Print
 Add Notes
 Bookmark this page
KeyValuePair in C#

The KeyValuePair class stores a pair of values in a single list with C#.
Set KeyValuePair and add elements −
var myList = new List<KeyValuePair<string, int>>();

// adding elements
myList.Add(new KeyValuePair<string, int>("Laptop", 20));
myList.Add(new KeyValuePair<string, int>("Desktop", 40));
myList.Add(new KeyValuePair<string, int>("Tablet", 60));
Here is the code to learn how to work with KeyValuePair and display the keys and values −
Using System;
using System.Collections.Generic;
class Program {
   static void Main() {
      var myList = new List<KeyValuePair<string, int>>();
      // adding elements
      myList.Add(new KeyValuePair<string, int>("Laptop", 20));
      myList.Add(new KeyValuePair<string, int>("Desktop", 40));
      myList.Add(new KeyValuePair<string, int>("Tablet", 60));
      foreach (var val in myList) {
         Console.WriteLine(val);
      }
   }
}
Program to check if an Array is Palindrome or not using STL in C++

Given an array arr[n] of n integers, the task is to find whether array is a palindrome or not. We have to do the stated task using STL in C++.
In C++ there is a feature of STL(Standard Template Library), it is a set of C++ template classes which are used to provide the data structures and several functions such as stacks, queues, lists, etc. To use these one must have knowledge of template classes.
Palindrome is a sequence which is read the same from the front or rear of the sequence. Some simple examples of a palindrome are − MADAM, RACECAR, etc. An array would be a palindrome like in the given example below −
So, the task is simple to find out whether the array is a palindrome or not using STL in C++ and print “its a palindrome” if it is a palindrome else “its not a palindrome” if it is not a palindrome.
Input
arr[] = {1, 2, 3, 5, 3, 2, 1}
Output
its a palindrome
Input
arr[] = {1, 2, 3, 4, 5}
Output
its not a palindrome
Set flag = 0 by default in the starting.
Set flag = 0 by default in the starting.
Loop the array i from 0 till size n/2
Loop the array i from 0 till size n/2
For every i check if arr[i]! = arr[n-i-1] then set the flag = 1 and break
For every i check if arr[i]! = arr[n-i-1] then set the flag = 1 and break
After the loop has ended, If flag is 1 the print “its a palindrome” else print “its not a palindrome”.
After the loop has ended, If flag is 1 the print “its a palindrome” else print “its not a palindrome”.
Start 1→ declare function to check if an array is palindrome or not
   void check_palindrome(int arr[], int size)
      declare int flag = 0
      Declare int arr_2[size]
      Call memcpy(arr_2, arr, size * sizeof(int))
      Call reverse(arr, arr + size)
      Loop For int i = 0 and i < size and i++
         IF (arr[i] != arr_2[i])
            Set flag = 1
            Break
         End
         IF (flag == 0)
            Print its a palindrome
         End
         Else
            Print its not a palindrome
         End
Step 2→ In main()
   Declare int arr[] = { 2,3,4,3,2 }
   Declare int size = sizeof(arr) / sizeof(arr[0])
   Call check_palindrome(arr, size)
 Live Demo
#include <bits/stdc++.h>
using namespace std;
void check_palindrome(int arr[], int size){
   int flag = 0;
   int arr_2[size];
   memcpy(arr_2, arr, size * sizeof(int));
   reverse(arr, arr + size);
   for (int i = 0; i < size; i++)
      if (arr[i] != arr_2[i]){
         flag = 1;
         break;
      }
      if (flag == 0)
         cout << "its a palindrome\n";
      else
         cout << "its not a palindrome\n";
}
int main(){
   int arr[] = { 2,3,4,3,2 };
   int size = sizeof(arr) / sizeof(arr[0]);
   check_palindrome(arr, size);
   return 0;
}
If run the above code it will generate the following output −
its a palindrome
HTML | <thead> valign Attribute - GeeksforGeeks

25 Feb, 2022
The HTML thead valign Attribute is used to specify the vertical alignment of content inside the thead Element.
Syntax:
<thead valign="top | middle | bottom | baseline">
Attribute values:
top: It sets the content to top-align.
middle: It sets the content to middle-align.
bottom: It sets the content to bottom-align.
baseline: It sets the content to baseline. The baseline is the line where most of the characters sit. It has a default value.
Note : The HTML
Example:
<!DOCTYPE html><html>  <head>    <title>HTML <thead> valign Attribute      </title>    <style>        h1 {            color: green;        }                  thead {            color: blue;        }                  table,        tbody,        td {            border: 1px solid black;            border-collapse: collapse;        }    </style></head>  <body>    <center>        <h1>GeeksforGeeks</h1>        <h2> HTML thead valign Attribute</h2>                <table>            <!-- thead tag starts from here -->            <thead align="char"                    valign="bottom"                    char="M">                <tr>                    <th>Name</th>                    <th>User Id</th>                </tr>            </thead>            <!-- thead tag ends here -->              <tbody>                <tr>                    <td>Ram</td>                    <td>@ram_b</td>                </tr>                <tr>                    <td>Shashank</td>                    <td>@shashankla</td>                </tr>            </tbody>        </table>            </center></body>  </html>
Output:
Supported Browsers: The browsers supported by HTML <thead> valign Attribute are listed below:
Google Chrome
Internet Explorer
Firefox
Apple Safari
Opera
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.
hritikbhatnagar2182
chhabradhanvi
HTML-Attributes
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?
Form validation using HTML and JavaScript
How to Insert Form Data into Database using PHP ?
How to set input type date in dd-mm-yyyy format using HTML ?
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to fetch data from an API in ReactJS ?
Express.js express.Router() Function
How to insert spaces/tabs in text using HTML/CSS?
Printing HELLO with turtle module - GeeksforGeeks

06 Oct, 2020
Turtle is a Python Module which allows us to draw a various geometrical illustration by just importing it in Python and using the inbuilt function of the turtle Module. We can use functions like turtle.forward(...) and turtle.right(...) which can move the turtle around. Turtle is a beginner-friendly way to learn python by running some basic commands and viewing the turtle do it graphically. It is like a drawing board that allows you to draw over it. The turtle module can be used in both object-oriented and procedure-oriented ways. 
Turtle methods used are as follows: 
 
position()– This function is used to get the coordinates/position of the turtle pointer. No parameter is required here as this function is not used for giving input but is used to output the position of turtle in the console window. 
 
Note: To know more about turtle click here. Example: 
python3
# Python program to# demonstrate basics of turtle # Importing and making a turtle object# with background color as whiteimport turtle frame = turtle.Screen().bgcolor("White")draw = turtle.Turtle()draw.left(90)draw.forward(100)draw.right(90)draw.forward(100)
Output:  
After having learned the basics of turtle, let’s write the code for printing ‘HELLO’. Below is the implementation. 
python3
# Python program to# demonstrate printing HELLO# using turtle # Here frame is initialized with# background colour as "White"import turtleframe = turtle.Screen().bgcolor("White")draw = turtle.Turtle() # The colour, width and speed of the pen is initializeddraw.color("Green")draw.width(3)draw.speed(10) # Now lets get started with actual code# printing letter Hdraw.left(90)draw.forward(70)draw.penup()draw.goto(0, 35)draw.pendown()draw.right(90)draw.forward(30)draw.penup()draw.goto(30, 70)draw.pendown()draw.right(90)draw.forward(70) # printing letter Edraw.penup()draw.goto(40, 0)draw.pendown()draw.right(180)draw.forward(70)draw.right(90)draw.forward(35)draw.penup()draw.goto(40, 35)draw.pendown()draw.forward(35)draw.penup()draw.goto(40, 0)draw.pendown()draw.forward(35) # printing letter Ldraw.penup()draw.goto(90, 70)draw.pendown()draw.right(90)draw.forward(70)draw.left(90)draw.forward(35) # printing letter Ldraw.penup()draw.goto(135, 70)draw.pendown()draw.right(90)draw.forward(70)draw.left(90)draw.forward(35) # printing letter Odraw.penup()draw.goto(210, 70)draw.pendown()for i in range(25):    draw.right(15)    draw.forward(10)
Output:  
 
pulkitagarwal03pulkit
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Python OOPs Concepts
How to Install PIP on Windows ?
Bar Plot in Matplotlib
Defaultdict in Python
Python Classes and Objects
Deque in Python
Check if element exists in list in Python
How to drop one or multiple columns in Pandas Dataframe
Python - Ways to remove duplicates from list
Class method vs Static method in Python
How to create and apply CSS to JavaScript Alert box?

The standard alert box in JavaScript does not provide the option to apply CSS. To style your alert box, you need to create a custom one first. The custom alert box will be created using jQuery and styles will be applied to CSS.
You can try to run the following code to learn how to create and apply CSS to alert box −
Live Demo
<!DOCTYPE html>
<html>
   <head>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script>
         function functionAlert(msg, myYes) {
            var confirmBox = $("#confirm");
            confirmBox.find(".message").text(msg);
            confirmBox.find(".yes").unbind().click(function() {
               confirmBox.hide();
            });
            confirmBox.find(".yes").click(myYes);
            confirmBox.show();
         }
      </script>
      <style>
         #confirm {
            display: none;
            background-color: #F3F5F6;
            color: #000000;
            border: 1px solid #aaa;
            position: fixed;
            width: 300px;
            height: 100px;
            left: 40%;
            top: 40%;
            box-sizing: border-box;
            text-align: center;
         }
         #confirm button {
            background-color: #FFFFFF;
            display: inline-block;
            border-radius: 12px;
            border: 4px solid #aaa;
            padding: 5px;
            text-align: center;
            width: 60px;
            cursor: pointer;
         }
         #confirm .message {
            text-align: left;
         }
      </style>
   </head>
   <body>
      <div id="confirm">
         <div class="message">This is a warning message.</div><br>
         <button class="yes">OK</button>
      </div>
      <input type="button" value="Click Me" onclick="functionAlert();" />
   </body>
 </html>
Bootstrap .btn-primary class

The .btn-primary class provides extra visual weight and identifies the primary action in a set of buttons:
Live Demo
<!DOCTYPE html>
<html>
   <head>
      <title>Bootstrap Example</title>
      <meta name = "viewport" content = "width=device-width, initial-scale=1">
      <link rel = "stylesheet" href = "https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script src = "https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
   </head>
   <body>
      <button type = "button" class = "btn btn-primary">Primary Button</button>
   </body>
</html>
How can we convert a JSON array to a list using Jackson in Java?


A Jackson is a Java-based library and it can be useful to convert Java objects to JSON and JSON to Java Object. A Jackson API is faster than other API, needs less memory area and is good for the large objects. We can convert a JSON array to a list using the ObjectMapper class. It has a useful method readValue() which takes a JSON string and converts it to the object class specified in the second argument.
import java.util.*;
import com.fasterxml.jackson.databind.*;
public class JSONArrayToListTest1 {
   public static void main(String args[]) {
      String jsonStr = "[\"INDIA\", \"AUSTRALIA\", \"ENGLAND\", \"SOUTH AFRICA\", \"WEST INDIES\"]";
      ObjectMapper objectMapper = new ObjectMapper();
      try {
         List<String> countries = objectMapper.readValue(jsonStr, List.class);
         System.out.println("The countries are:\n " + countries);
      } catch(Exception e) {
         e.printStackTrace();
      }
   }
}
The countries are:
[INDIA, AUSTRALIA, ENGLAND, SOUTH AFRICA, WEST INDIES]
What are Python function attributes?

Everything in Python is an object, and almost everything has attributes and methods. In python, functions too are objects. So they have attributes like other objects. All functions have a built-in attribute __doc__, which returns the doc string defined in the function source code. We can also assign new attributes to them, as well as retrieve the values of those attributes.
For handling attributes, Python provides us with “getattr” and “setattr”, a function that takes three arguments. There is no difference between “setattr” and using the dot-notation on the left side of the = assignment operator:
The given code can be written as follows to assign and retrieve attributes.
def foo():
    pass
setattr(foo, 'age', 23 )
setattr(foo, 'name', 'John Doe' )
print(getattr(foo, 'age'))
foo.gender ='male'
print(foo.gender)
print(foo.name)
print(foo.age)
C:/Users/TutorialsPoint1/~.py
23
male
John Doe
23
C++ Program to Implement the linear congruential generator for Pseudo Random Number Generation

The linear congruential generator is a very simple example of a random number generator. It is one of the oldest and best-known pseudorandom number generator algorithms. The function which is used in this method −
Xn+1=(aXn + C) mod m
where X is the sequence of pseudorandom values, and
m,0<m— the “modulus"
a,0<a<m — the "multiplier"
c,0<c<m — the "increment"
X0, 0<x0<m — the "seed" or "start value"
are integer constants that specify the generator.
A benefit of this method is is that with appropriate choice of parameters, the period is known and long.
Begin
   Declare class mRND
   Create a function Seed(number)
      Assign a variable _seed=number
      Create a constructor mRND
   Declare _seed(0), a(0), c(0), m(2147483648)
   Create a function rnd()
      Return
         _seed = (a * _seed + c) mod m
      Declare a, c, m, _seed
   Done
   Declare an another subclass MS_RND inheriting from base class mRND
   Create a constructor
      Read the variables a, c
      Create a function rnd()
      return mRND::rnd() right shift 16
   Done
   Declare an another subclass BSD_RND inheriting from base class mRND
   Create a constructor
      Read the variables a, c
      Create a function rnd()
      return mRND::rnd()
   Done
   For x=0 to 6
      Print MS_RAND
   For x=0 to 6
      Print BSD_RAND
   Done
End
#include <iostream>
using namespace std;
class mRND {
   public:
   void seed(unsigned int s) {
      _seed= s;
   }
   protected:
   mRND() :
   _seed(0), a(0), c(0), m(2147483648) { }
   int rnd() {
      return (_seed = (a * _seed + c) % m);
   }
   int a, c;
   unsigned int m, _seed;
};
class MS_RND: public mRND {
   public:
   MS_RND() {
      a = 214013;
      c = 2531011;
   }
   int rnd() {
      return mRND::rnd() >> 16;
   }
};
class BSD_RND: public mRND {
   public:
   BSD_RND() {
      a = 1016404597;
      c = 12345;
   }
   int rnd() {
      return mRND::rnd();
   }
};
int main(int argc, char* argv[]) {
   BSD_RND bsd_rnd;
   MS_RND ms_rnd;
   cout << "MS RAND:" << endl << "-----------" << endl;
   for (int x = 0; x < 6; x++)
      cout << ms_rnd.rnd() << endl;
   cout << endl << "BSD RAND:" << endl << "-------------" << endl;
   for (int x = 0; x < 6; x++)
      cout << bsd_rnd.rnd() << endl;
      return 0;
}
MS RAND:
-------
38
7719
21238
2437
8855
11797
BSD RAND:
--------
12345
1915290694
1005338679
629284700
741596485
1834373826