code-rag-bench/online-tutorials huggingface dataset:
Matplotlib.ticker.MaxNLocator Class in Python - GeeksforGeeks

21 Apr, 2020
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.
The matplotlib.ticker.MaxNLocator class is used to select no more than N intervals at nice locations. It is a subclass of matplotlib.ticker.Locator.
Syntax: class matplotlib.ticker.MaxNLocator(*args, **kwargs)
Parameter:
nbins: It is either an integer or ‘auto’, where the integer value represents the maximum number of intervals; one less than max number of ticks. The number of bins gets automatically determined on the basis of the length of the axis.It is an optional argument and has a default value of 10.
steps: It is an optional parameter representing a nice number sequence that starts from 1 and ends with 10.
integer: It is an optional boolean value. If set True, the ticks accepts only integer values, provided at least min_n_ticks integers are within the view limits.
symmetric: It is an optional value. If set to True, auto-scaling will result in a range symmetric about zero.
prune: It is an optional parameter that accepts either of the four values: {‘lower’, ‘upper’, ‘both’, None}. By default it is None.
Methods of the class:
set_params(self, **kwargs): It sets parameters for the locator.
tick_values(self, vmin, vmax): It returns the values of the located ticks given vmin and vmax.
view_limits(self, dmin, dmax): It is used to select a scale for the range from vmin to vmax.
Example 1:
import matplotlib.pyplot as pltfrom matplotlib import tickerimport numpy as np    N = 10x = np.arange(N)y = np.random.randn(N)  fig = plt.figure()ax = fig.add_subplot(111)ax.plot(x, y)  # Create your ticker object with M ticksM = 3yticks = ticker.MaxNLocator(M)  # Set the yaxis major locator using# your ticker object. ax.yaxis.set_major_locator(yticks)  plt.show()
Output:
Example 2:
import matplotlib.pyplot as pltfrom matplotlib.ticker import MaxNLocator, IndexFormatter    ax = df.plot()  ax.xaxis.set_major_locator(MaxNLocator(11))ax.xaxis.set_major_formatter(IndexFormatter(df.index))   ax.grid(which ='minor', alpha = 0.2)ax.grid(which ='major', alpha = 0.5)  ax.legend().set_visible(False)plt.xticks(rotation = 75)plt.tight_layout()  plt.show()
Output:
Python-matplotlib
Python
Write From Home
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
Convert string to integer in Python
Python infinity
Quadratic Probing in Hashing
Matplotlib.pyplot.title() in Python
How to set input type date in dd-mm-yyyy format using HTML ?
Java do Keyword

❮ Java Keywords

The following loop will always be executed at least once, even if the condition is false, because the code block is executed before the condition is tested:
int i = 0;
do {
  System.out.println(i);
  i++;
}
while (i < 5);


Try it Yourself »

The do keyword is used together with while to create a do-while loop.
The while loop loops through a block of code as long as a specified condition is true:
The do/while loop is a variant of the while loop. This loop will 
execute the code block once, before checking if the condition is true, then it will
repeat the loop as long as the condition is true.
Note: Do not forget to increase the variable used in the condition, otherwise 
the loop will never end!
Read more about while loops in our Java While Loop Tutorial.

❮ Java Keywords

We just launchedW3Schools videos
Get certifiedby completinga course today!
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
help@w3schools.com
Your message has been sent to W3Schools.
PHP floor() Function

The floor() function is another in-built function in PHP iterpreter. This function accepts any float number as argument and rounds it down to the next lowest integer.
This function always returns a float number as range of float is bigger than that of integer.
floor ( float $num ) : float
PHP floor() function returns the largest integer less than or equal to given parameter.
This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.
 Live Demo
Following example rounds 15.05 to its next highest integer which is 15
<?php
   $arg=15.05;
   $val=floor($arg);
   echo "floor(" . $arg . ") = " . $val;
?>
This will produce following result −
floor(15.05) = 15
 Live Demo
Following example shows that next lowest integer to 5.78 is 5.−
<?php
   $arg=5.78;
   $val=floor($arg);
   echo "floor(" . $arg . ") = " . $val;
?>
This will produce following result −
floor(5.78) = 5
 Live Demo
The floor() function returns 0 for a string parameter −
<?php
   $arg="Hello";
   $val=floor($arg);
   echo "floor(" . $arg . ") = " . $val;
?>
This will produce following result −
floor(Hello) = 0
 Live Demo
For negative number, it is rounded away from 0 −
<?php
   $arg=-3.95;
   $val=floor($arg);
   echo "floor(" . $arg . ") = " . $val;
?>
This will produce following result −
floor(-3.95) = -4
Keyed Hash for Message Authentication using Python

The HMAC is a framework, it is used to message authentication using cryptographic hash functions. HMAC can be used for MD5, SHA-1 etc.
The basic idea to generate cryptographic hash, is perform the hashing on the actual data and secret key. The final output is sent without the secret key.
To use this module, we need to import the hmac module in the python code.
import hmac

Some methods and attributes of the hmac module are as follows −
This method is used to update the hmac object with the given message. Repeated call of this function is equivalent with the single call with concatenated arguments.
This method is used to return the digested data which is passed through the update method. The size of the byte object is same as the digest_size. It may contain bytes in the whole range from 0 to 255.
This method is same as the digest method but the result will contain only hexadecimal values. This method is used to send data through the internet very easily.
This method is used to make a copy of the hmac object. To compute the digest of strings in a more efficient way, the copy() method is useful.
import hashlib
import hmac
update_bytes = b'Python123'
password = b'abcde1234'
my_hmac = hmac.new(update_bytes, password, hashlib.md5) #Create hash using md5 algorithm
print("The first digest: " + str(my_hmac.digest()))
print("The Canonical Name: " + my_hmac.name)
my_hmac_cpy = my_hmac.copy() #Create a copy of the hmac object
print("The Copied digest: " + str(my_hmac_cpy.digest()))
The first digest: b"\x1c\xe1\xfb\x9b\xd4\x8bu\xb9\xe6N6\xee\x00O'}"
The Canonical Name: hmac-md5
The Copied digest: b"\x1c\xe1\xfb\x9b\xd4\x8bu\xb9\xe6N6\xee\x00O'}"
PostgreSQL - SELECT Query

PostgreSQL SELECT statement is used to fetch the data from a  database table, which returns data in the form of result table.  These result tables are called result-sets.
The basic syntax of SELECT statement is as follows −
SELECT column1, column2, columnN FROM table_name;

Here, column1, column2...are the fields of a table, whose values you want to fetch. If you want to fetch all the fields available in the field then you can use the following syntax −
SELECT * FROM table_name;
Consider the table COMPANY having records as follows −
 id | name  | age | address   | salary
----+-------+-----+-----------+--------
  1 | Paul  |  32 | California|  20000
  2 | Allen |  25 | Texas     |  15000
  3 | Teddy |  23 | Norway    |  20000
  4 | Mark  |  25 | Rich-Mond |  65000
  5 | David |  27 | Texas     |  85000
  6 | Kim   |  22 | South-Hall|  45000
  7 | James |  24 | Houston   |  10000
(7 rows)
The following is an example, which would fetch ID, Name and Salary fields of the customers available in CUSTOMERS table −
testdb=# SELECT ID, NAME, SALARY FROM COMPANY ;
This would produce the following result −
  id | name  | salary
 ----+-------+--------
   1 | Paul  |  20000
   2 | Allen |  15000
   3 | Teddy |  20000
   4 | Mark  |  65000
   5 | David |  85000
   6 | Kim   |  45000
   7 | James |  10000
(7 rows)

If you want to fetch all the fields of CUSTOMERS table, then use the following query −
testdb=# SELECT * FROM COMPANY;
This would produce the following result −
 id | name  | age | address   | salary
----+-------+-----+-----------+--------
  1 | Paul  |  32 | California|  20000
  2 | Allen |  25 | Texas     |  15000
  3 | Teddy |  23 | Norway    |  20000
  4 | Mark  |  25 | Rich-Mond |  65000
  5 | David |  27 | Texas     |  85000
  6 | Kim   |  22 | South-Hall|  45000
  7 | James |  24 | Houston   |  10000
(7 rows)


    23 Lectures 
     1.5 hours 

 John Elder

    49 Lectures 
     3.5 hours 

 Niyazi Erdogan

    126 Lectures 
     10.5 hours 

 Abhishek And Pukhraj

    35 Lectures 
     5 hours 

 Karthikeya T

    5 Lectures 
     51 mins

 Vinay Kumar

    5 Lectures 
     52 mins

 Vinay Kumar
 Print
 Add Notes
 Bookmark this page
Tryit Editor v3.7 - Show Java

import java.util.*; // import the java.util package 

class Main {
  public static void main(String[] args) {
    Scanner myObj = new Scanner(System.in);
    String userName;
    
    // Enter username and press Enter
    System.out.println("Enter username"); 
    userName = myObj.nextLine();   
       
    System.out.println("Username is: " + userName);
What is Transitive dependency in DBMS?

A functional dependency X->Y is a transitive dependency, if X is not candidate key or super key and Y is a non-key attribute(s).
Let a relation be R(A,B,C)
Thus, Key attribute = A and Non-key attribute =B,C.
B->C is a transitive dependency.
Let's consider another example, where a relation is R(A,B.C.D)
Thus, Key attributes = A,B and Non-key attributes = C,D.
Then, C->D is a Transitive dependency
AB-> D is not a transitive dependency
C->DB is not a transitive dependency.
A relation R(ABCDEF) and F: {AB->C, C->A, B->DE, ABD-> F}. Find the transitive dependency.
AB+=ABCDE => AB is candidate key
C+=CA
B+=BDE
ABD+=ABDFCE =>ABD is not candidate key [since AB is candidate key]
=>key attribute= {A,B} and non-key attributes ={C,D,E}
AB-> C is not a transitive dependency
C->A is not a transitive dependency
B->DE is a transitive dependency [Since, B is not a candidate key/super key and DE is a non-key attribute}.
ABD->F is not a transitive dependency. [Since, ABD is a super key].
Consider the table given below −
The dependencies are as follows −
{Book} -> {Book_Author}
{Book_Author} does not -> {Book}
{Book_Author} -> {Age_of_Author}
Hence, as per the transitivity, the {Book} -> {Age_of_Author}. Therefore, if one knows the book, then the age of the Author is also known.
How to handle when checkbox 'checked state' changed event in jQuery?

To handle the checkbox checked state, use the change event. It will check whether the checkox is checked or not.
You can try to run the following code to learn how to handle when checkbox checked state changed event in jQuery −
Live Demo
<!doctype html>
<html>
<head>
  <title>jQuery Checkbox state</title>
  <style>
  b {
    color: red;
  }
  </style>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
<input id="checkbox1" type="checkbox" checked="checked">
<label for="checkbox1">Check/ Uncheck this checkbox</label>
<p></p>
 
<script>
$( "input" ).change(function() {
  var $input = $( this );
  $( "p" ).html(
    ".attr( \"checked\" ): <b>" + $input.attr( "checked" ) + "</b><br>" +
    ".prop( \"checked\" ): <b>" + $input.prop( "checked" ) + "</b><br>" +
    ".is( \":checked\" ): <b>" + $input.is( ":checked" ) + "</b>" );
}).change();
</script>
 
</body>
</html>
Even numbers at even index and odd numbers at odd index in C++

In this problem, we are given an array arr[] of size n consisting of n/2 even values and n/2 odd values. Our task is to create a program to place even numbers at even index and odd numbers at odd index. 
Input: arr[] = {5, 1, 6, 4, 3, 8}
Output: arr[] = {6, 1, 5, 4, 3, 8}
A solution would be traversing the array and then find the end number which is not at even position and replacing it with the next off place value. This is a promising solution but the solution can be made more efficient by using two indexes one for even and one for odd. If there is an element at even index which is not even and an odd element which is not at odd index, we will swap them otherwise increase both indices by two.
Live Demo
#include <iostream>
using namespace std;

void O_EReshuffle(int arr[], int n) {
   
   int oIndex = 1;
   int eIndex = 0;
   
   for(int i = 0; i < n; ) {
     
      while (eIndex < n && arr[eIndex] % 2 == 0)
         eIndex += 2;
         
      while (oIndex < n && arr[oIndex] % 2 == 1)
         oIndex += 2;
         
      if (eIndex < n && oIndex < n)
         swap (arr[eIndex], arr[oIndex]);
         
      else
         break;
   }
}

int main()
{
   int arr[] = { 5, 1, 6, 4, 3, 8 };
   int n = sizeof(arr) / sizeof(arr[0]);

   cout << "Array before Reshuffling: ";
   for(int i = 0; i < n ; i++){
      cout<<arr[i]<<"\t";
   }
   O_EReshuffle(arr, n);

   cout<<"\nArray after Reshuffling: ";
   for(int i = 0; i < n ; i++){
      cout<<arr[i]<<"\t";
   };

   return 0;
}
Array before Reshuffling: 5 1 6 4 3 8
Array after Reshuffling: 4 1 6 5 8 3
C Library - <assert.h>

The assert.h header file of the C Standard Library provides a macro called assert which can be used to verify assumptions made by the program and print a diagnostic message if this assumption is false.
The defined macro assert refers  to another macro NDEBUG which is not a part of <assert.h>. If NDEBUG is defined as a macro name in the source file, at the point where <assert.h> is included, the assert macro is defined as follows −
#define assert(ignore) ((void)0)
Following is the only function defined in the header assert.h −
This is actually a macro and not a function, which can be used to add diagnostics in your C program.

    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
What is the equivalent of SQL “like” in MongoDB?

You can use “$regex” operator to implement the equivalent of SQL ‘like’ in MongoDB. To implement it, let us create a collection with a document. The query to create a collection with a document is as follows −
> db.sqlLikeDemo.insertOne({"UserName":"John Smith","UserAge":24});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c912e124afe5c1d2279d6a5")
}
> db.sqlLikeDemo.insertOne({"UserName":"John Doe","UserAge":21});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c912e264afe5c1d2279d6a6")
}
> db.sqlLikeDemo.insertOne({"UserName":"Chris Williams","UserAge":22});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c912e404afe5c1d2279d6a7")
}
> db.sqlLikeDemo.insertOne({"UserName":"Robert Taylor","UserAge":26});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c912e4d4afe5c1d2279d6a8")
}
> db.sqlLikeDemo.insertOne({"UserName":"John Brown","UserAge":27});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c912e6c4afe5c1d2279d6a9")
}
> db.sqlLikeDemo.insertOne({"UserName":"Mike Brown","UserAge":23});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c912e794afe5c1d2279d6aa")
}
> db.sqlLikeDemo.insertOne({"UserName":"Larry Smith","UserAge":24});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c912e8c4afe5c1d2279d6ab")
}
Display all documents from a collection with the help of find() method. The query is as follows −
> db.sqlLikeDemo.find().pretty();
The following is the output −
{
   "_id" : ObjectId("5c912e124afe5c1d2279d6a5"),
   "UserName" : "John Smith",
   "UserAge" : 24
}
{
   "_id" : ObjectId("5c912e264afe5c1d2279d6a6"),
   "UserName" : "John Doe",
   "UserAge" : 21
}
{
   "_id" : ObjectId("5c912e404afe5c1d2279d6a7"),
   "UserName" : "Chris Williams",
   "UserAge" : 22
}
{
   "_id" : ObjectId("5c912e4d4afe5c1d2279d6a8"),
   "UserName" : "Robert Taylor",
   "UserAge" : 26
}
{
   "_id" : ObjectId("5c912e6c4afe5c1d2279d6a9"),
   "UserName" : "John Brown",
   "UserAge" : 27
}
{
   "_id" : ObjectId("5c912e794afe5c1d2279d6aa"),
   "UserName" : "Mike Brown",
   "UserAge" : 23
}
{
   "_id" : ObjectId("5c912e8c4afe5c1d2279d6ab"),
   "UserName" : "Larry Smith",
   "UserAge" : 24
}
Here is the query that works like SQL ‘like’ clause i.e. the record with “UserName” John −
> db.sqlLikeDemo.find({"UserName":{"$regex": "John"}}).pretty();
The following is the output −
{
   "_id" : ObjectId("5c912e124afe5c1d2279d6a5"),
   "UserName" : "John Smith",
   "UserAge" : 24
}
{
   "_id" : ObjectId("5c912e264afe5c1d2279d6a6"),
   "UserName" : "John Doe",
   "UserAge" : 21
}
{
   "_id" : ObjectId("5c912e6c4afe5c1d2279d6a9"),
   "UserName" : "John Brown",
   "UserAge" : 27
}
Python Program to add two hexadecimal numbers

27 May, 2022
Given two hexadecimal numbers, write a Python program to compute their sum.
Examples:
Input: a = "01B", b = "378" 
Output: 393 
Explanation: B (11 in decimal) + 8 = 19 (13 in hex), hence addition bit = 3, 
             carry = 1 1 + 7 + 1 (carry) = 9, hence addition bit = 9, 
             carry = 0 0 + 3 + 0 (carry) = 3, hence addition bit = 3, 
             carry = 0 01B + 378 = 393 
Input: a = "AD", b = "1B" 
Output: C8 
Explanation: D(13 in Dec) + B(11 in Dec) = 24(18 in hex), 
              hence addition bit = 8, carry = 1 A(10 in Dec) + 1 + 1 (carry)= 12 (C in hex), 
              addition bit = C carry = 0 AD + 1B = C8
Approach:
To add two hexadecimal values in python we will first convert them into decimal values then add them and then finally again convert them to a hexadecimal value. To convert the numbers we will make use of the hex() function The hex() function is one of the built-in functions in Python3, which is used to convert an integer number into its corresponding hexadecimal form. We will also use the int() function to convert the number to decimal form. The int() function in Python and Python3 converts a number in the given base to decimal.
Below are the implementations based on the above approach:
Example 1:
Python3
# Python program to add two hexadecimal numbers. # Driver code# Declaring the variablesa = "01B"b = "378" # Calculating hexadecimal value using functionsum = hex(int(a, 16) + int(b, 16)) # Printing resultprint(sum[2:])
393

Example 2:
Python3
# Python program to add two hexadecimal numbers. # Driver code# Declaring the variablesa = "B"b = "C" # Calculating hexadecimal value using functionsum = hex(int(a, 16) + int(b, 16)) # Printing resultprint(sum[2:])
17

Example 3:
Python3
# Python program to add two hexadecimal numbers. # Driver codeif __name__ == "__main__" :     # Declaring the variables    a = "01B"    b = "378"         # Calculating hexadecimal sum by using hex() and int()    hexadecimal_sum = lambda a,b : hex(int(a, 16) + int(b, 16))         # calling hexadecimal_sum lambda function    print(hexadecimal_sum(a,b)[2:])
393

ankthon
Numbers
Python
Python Programs
Numbers
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Python Classes and Objects
Python OOPs Concepts
Introduction To PYTHON
How to drop one or multiple columns in Pandas Dataframe
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Python Program for Fibonacci numbers
Python | Split string into list of characters
Python | Alternate cases in String

26 Oct, 2021
The problem of case changes a string is quite common and has been discussed many times. Sometimes, we might have a problem like this in which we need to convert the odd character of string to upper case and even positioned characters to lowercase. Let’s discuss certain ways in which this can be performed.Method #1 : Using upper() + lower() + loop This task can be performed in brute force method in a way that we iterate through the string and convert odd elements to uppercase and even to lower case using upper() and lower() respectively. 
Python3
# Python3 code to demonstrate working of# Alternate cases in String# Using upper() + lower() + loop # initializing stringtest_str = "geeksforgeeks" # printing original stringprint("The original string is : " + str(test_str)) # Using upper() + lower() + loop# Alternate cases in Stringres = ""for idx in range(len(test_str)):    if not idx % 2 :       res = res + test_str[idx].upper()    else:       res = res + test_str[idx].lower() # printing resultprint("The alternate case string is : " + str(res))
The original string is : geeksforgeeks
The alternate case string is : GeEkSfOrGeEkS

 Method #2 : Using list comprehension This is the shortened one liner approach to this problem. It uses same logic as above but in much more compact way. 
Python3
# Python3 code to demonstrate working of# Alternate cases in String# Using list comprehension # initializing stringtest_str = "geeksforgeeks" # printing original stringprint("The original string is : " + str(test_str)) # Using list comprehension# Alternate cases in Stringres = [ele.upper() if not idx % 2 else ele.lower() for idx, ele in enumerate(test_str)]res = "".join(res) # printing resultprint("The alternate case string is : " + str(res))
The original string is : geeksforgeeks
The alternate case string is : GeEkSfOrGeEkS

simmytarika5
Python list-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Different ways to create Pandas Dataframe
Enumerate() in Python
Python String | replace()
How to Install PIP on Windows ?
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Python | Convert string dictionary to dictionary
Python Program for Fibonacci numbers
Python program to extract key-value pairs with substring in a dictionary

01 Oct, 2020
Given a dictionary list, extract all the dictionaries which have substring present in particular key.
Input : [{“Gfg” : “4”, “best” : “1”}, {“Gfg” : “good CS content”, “best” : “10”}], K = “Gfg”, sub_str = “CS” Output : [{‘Gfg’: ‘good CS content’, ‘best’: ’10’}] Explanation : “Gfg” has “CS” as substring value.
Input : [{“Gfg” : “4”, “best” : “1”}, {“Gfg” : “good content”, “best” : “10”}], K = “Gfg”, sub_str = “CS” Output : [] Explanation : No dictionary with “CS” as substring to “Gfg” key. 
Method #1 : Using list comprehension
This is one of the ways in which this task can be performed. In this, we iterate for all the dictionaries and check for key’s value substring presence using in operator.
Python3
# Python3 code to demonstrate working of# Dictionaries with Substring values# Using list comprehension  # initializing liststest_list = [{"Gfg": "4", "best": "1"},             {"Gfg": "good for CS", "best": "8"},             {"Gfg": "good CS content", "best": "10"}]  # printing original listprint("The original list : " + str(test_list))  # initializing K keyK = "Gfg"  # initializing target valuesub_str = "CS"  # list comprehension to extract values with# substring values using in operatorres = [val for val in test_list if sub_str in val[K]]  # printing resultprint("Dictionaries with particular substring values : " + str(res))
Output:
The original list : [{‘Gfg’: ‘4’, ‘best’: ‘1’}, {‘Gfg’: ‘good for CS’, ‘best’: ‘8’}, {‘Gfg’: ‘good CS content’, ‘best’: ’10’}]Dictionaries with particular substring values : [{‘Gfg’: ‘good for CS’, ‘best’: ‘8’}, {‘Gfg’: ‘good CS content’, ‘best’: ’10’}]
Method #2 :  Using map() + in operator
This is yet another way in which this task can be performed. In this, we extract all the values with required substring using map() + lambda function. The in operator is used to check for substring inside the key’s value.
Python3
# Python3 code to demonstrate working of# Dictionaries with Substring values# Using map() + in operator  # initializing liststest_list = [{"Gfg": "4", "best": "1"},             {"Gfg": "good for CS", "best": "8"},             {"Gfg": "good CS content", "best": "10"}]  # printing original listprint("The original list : " + str(test_list))  # initializing K keyK = "Gfg"  # initializing target valueval = "CS"  # map() used to perform filteringres = list(map(lambda sub: val in sub[K], test_list))res = [test_list[idx] for idx, ele in enumerate(res) if res[idx]]  # printing resultprint("Dictionaries with particular substring values : " + str(res))
Output:
The original list : [{‘Gfg’: ‘4’, ‘best’: ‘1’}, {‘Gfg’: ‘good for CS’, ‘best’: ‘8’}, {‘Gfg’: ‘good CS content’, ‘best’: ’10’}]Dictionaries with particular substring values : [{‘Gfg’: ‘good for CS’, ‘best’: ‘8’}, {‘Gfg’: ‘good CS content’, ‘best’: ’10’}]
Python dictionary-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Pipelining vs Non-Pipelining

05 Oct, 2021
What is Pipelining Pipelining is accumulating the instructions from the processor through a pipeline or a data pipeline. A Pipeline is a set of data processing units arranged in series such that the output of one element is the input of the subsequent element. Pipelining is a technique in which multiple instructions are overlapped during execution. It is used primarily to create and organize instructions in a processor so that the processes run in concurrent fashion. Basically, Pipelining is a process to manage the addition of new tasks frequently by removing the completed tasks. 
Difference between Pipelining and Non-Pipelining: 
simmytarika5
rajeev0719singh
Computer Organization & Architecture
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Computer Architecture | Flynn's taxonomy
I2C Communication Protocol
Architecture of Distributed Shared Memory(DSM)
ARM processor and its Features
Direct Access Media (DMA) Controller in Computer Architecture
Introduction of Multiprocessor and Multicomputer
Architecture of 8085 microprocessor
8085 program to add two 16 bit numbers
Differences between Computer Architecture and Computer Organization
numpy.floor_divide() in Python

29 Nov, 2018
numpy.floor_divide(arr1, arr2, /, out = None, where = True, casting = ‘same_kind‘, order = ‘K‘, dtype = None) :
Array element from first array is divided by the elements from second array(all happens element-wise). Both arr1 and arr2 must have same shape.It is equivalent to the Python // operator and pairs with the Python % (remainder), function so that b = a % b + b * (a // b) up to roundoff.
Parameters :
arr1     : [array_like]Input array or object which works as numerator.

arr2     : [array_like]Input array or object which works as denominator. 

out      : [ndarray, None, optional]Output array with same dimensions as
           Input array, placed with result.

**kwargs : Allows you to pass keyword variable length of argument to a function. 
            It is used when we want to handle named argument in a function.

where    : [array_like, optional]True value means to calculate the universal 
            functions(ufunc) at that position, False value means to leave the 
            value in the output alone.

Return :
An array with floor(x1 / x2)

 Code 1 : arr1 divided by arr2
# Python program explaining# floor_divide() functionimport numpy as np  # input_arrayarr1 = [2, 2, 2, 2, 2]arr2 = [2, 3, 4, 5, 6]print ("arr1         : ", arr1)print ("arr1         : ", arr2)  # output_arrayout = np.floor_divide(arr1, arr2)print ("\nOutput array : ", out)
Output :
arr1         :  [2, 2, 2, 2, 2]
arr1         :  [2, 3, 4, 5, 6]

Output array :  [1 0 0 0 0]

 Code 2 : elements of arr1 divided by divisor
# Python program explaining# floor_divide() functionimport numpy as np  # input_arrayarr1 = [2, 7, 3, 11, 4]divisor = 3print ("arr1         : ", arr1)  # output_arrayout = np.floor_divide(arr1, divisor)print ("\nOutput array : ", out)
Output :
arr1         :  [2, 7, 3, 11, 4]

Output array :  [0 2 1 3 1]
 Code 3 : floor_divide handling results if arr2 has -ve elements
# Python program explaining# floor_divide() functionimport numpy as np  # input_arrayarr1 = [2, 6, 21, 21, 12]arr2 = [2, 3, 4, -3, 6]print ("arr1         : ", arr1)print ("arr2         : ", arr2)  # output_arrayout = np.floor_divide(arr1, arr2)print ("\nOutput array : ", out)
Output :
arr1         :  [2, 6, 21, 21, 12]
arr2         :  [2, 3, 4, -3, 6]

Output array :  [ 1  2  5 -7  2]
References :https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.floor_divide.html.
Python numpy-Mathematical Function
Python-numpy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Rotate axis tick labels in Seaborn and Matplotlib
Enumerate() in Python
Deque in Python
Stack in Python
sum() function in Python
Print lists in Python (5 Different Ways)
Different ways to create Pandas Dataframe
Queue in Python
Defaultdict in Python
How to iterate through Excel rows in Python?
JSP - Include Directive

The include directive is used to include a file during the translation phase. This directive tells the container to merge the content of other external files with the current JSP during the translation phase. You may code include directives anywhere in your JSP page.
The general usage form of this directive is as follows −
<%@ include file = "relative url" >

The filename in the include directive is actually a relative URL. If you just specify a filename with no associated path, the JSP compiler assumes that the file is in the same directory as your JSP.
You can write the XML equivalent of the above syntax as follows −
<jsp:directive.include file = "relative url" />

A good example of the include directive is including a common header and footer with multiple pages of content.
Let us define following three files (a) header.jsp, (b)footer.jsp, and (c)main.jsp as follows −
Following is the content of header.jsp −
<%! 
   int pageCount = 0;
   void addCount() {
      pageCount++;
   }
%>

<% addCount(); %>

<html>
   <head>
      <title>The include Directive Example</title>
   </head>
   
   <body>
      <center>
         <h2>The include Directive Example</h2>
         <p>This site has been visited <%= pageCount %> times.</p>
      </center>
      <br/><br/>
Following is the content of footer.jsp −
      <br/><br/>
      <center>
         <p>Copyright © 2010</p>
      </center>
   </body>
</html>
Finally here is the content of main.jsp −
<%@ include file = "header.jsp" %>
<center>
   <p>Thanks for visiting my page.</p>
</center>
<%@ include file = "footer.jsp" %>
Let us now keep all these files in the root directory and try to access main.jsp. You will receive the following output −
The include Directive Example

This site has been visited 1 times.

Thanks for visiting my page.

Copyright © 2010

Refresh main.jsp and you will find that the page hit counter keeps increasing.
You can design your webpages based on your creative instincts; it is recommended you keep the dynamic parts of your website in separate files and then include them in the main file. This makes it easy when you need to change a part of your webpage.
GATE | Gate IT 2008 | Question 17 - GeeksforGeeks

14 Feb, 2018
How many bytes of data can be sent in 15 seconds over a serial link with baud rate of 9600 in asynchronous mode with odd parity and two stop bits in the frame?(A) 10,000 bytes(B) 12,000 bytes(C) 15,000 bytes(D) 27,000 bytesAnswer: (B)Explanation:  Background required – Physical Layer in OSI Stack
In serial Communications, information is transferred in or out one bit at a time.The baud rate specifies how fast data is sent over a serial line. It’s usually expressed in units of bits-per-second (bps). Each block (usually a byte) of data transmitted is actually sent in a packet or frame of bits. Frames are created by appending synchronization and parity bits to our data.
"9600 baud" means that the serial port is capable of transferring a 
maximum of 9600 bits per second.

1 sec--------> 9600 bits
15 sec------->9600*15 bits

Total Data To send in 1 frame = 1 bit(start) + 8 bits(char size) + 1 bit(Parity) + 2 bits(Stop) 

= 12 bits.

Number of 8-bit characters that can be transmitted per second  = (9600 * 15)/12 = 12000 bytes.

This explanation is contributed by Pranjul Ahuja.
Quiz of this Question
Gate IT 2008
GATE-Gate IT 2008
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
GATE | GATE-CS-2016 (Set 2) | Question 48
GATE | GATE-CS-2014-(Set-1) | Question 30
GATE | GATE-CS-2001 | Question 23
GATE | GATE-CS-2015 (Set 1) | Question 65
GATE | GATE CS 2010 | Question 45
GATE | GATE-CS-2014-(Set-1) | Question 65
GATE | GATE-CS-2004 | Question 3
GATE | GATE-CS-2015 (Set 3) | Question 65
C++ Program to count Vowels in a string using Pointer
GATE | GATE CS 2012 | Question 40
How to convert signed to unsigned integer in Python ? - GeeksforGeeks

05 Apr, 2021
Python contains built-in numeric data types as int(integers), float, and complex. Compared to C programming, Python does not have signed and unsigned integers as data types. There is no need to specify the data types for variables in python as the interpreter itself predicts the variable data type based on the value assigned to that variable. The int data type in python simply the same as the signed integer.  A signed integer is a 32-bit integer in the range of -(2^31) = -2147483648 to (2^31) – 1=2147483647 which contains positive or negative numbers. It is represented in two’s complement notation. An unsigned integer is a 32-bit non-negative integer(0 or positive numbers) in the range of 0 to 2^32-1.  So, in this article let us know how to convert signed integer to unsigned integer in python.
Example 1: Add 2^32(or 1 << 32) to a signed integer to convert it to an unsigned integer
Python3
signed_integer = -100  # Adding 2^32 to convert signed to unsigned integerunsigned_integer = signed_integer+2**32print(unsigned_integer)print(type(unsigned_integer))
Output:
4294967196
<class 'int'>
Example 2: Using Bitwise left shift(<<) operator
Bitwise left shift: It performs bit manipulation by shifting the left operand bits of the number to the left and fills 0 on voids left as a result. 
 For example, x << y
Left shifts the integer ‘x’ with ‘y’ integer by y places. It is the same as multiplying x with 2 raised to the power of y(2**y).
Python3
signed_integer = -1  # Adding 1<<32 to convert signed to # unsigned integerunsigned_integer = signed_integer+(1 << 32)print(unsigned_integer)
Output:
4294967295
Example 3:
Python3
signed_integer = -10  # Adding 1<<32 to convert signed to# unsigned integerunsigned_integer = signed_integer+(1 << 32)print(unsigned_integer)
Output:
4294967286
Picked
python-basics
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Box Plot in Python using Matplotlib
Bar Plot in Matplotlib
Python | Get dictionary keys as a list
Python | Convert set into a list
Ways to filter Pandas DataFrame by column values
Python - Call function from another file
loops in python
Multithreading in Python | Set 2 (Synchronization)
Python Dictionary keys() method
Python Lambda Functions
Python program to find common elements in three lists using sets

26 Oct, 2018
Prerequisite : Sets in Python
Given three arrays, we have to find common elements in three sorted lists using sets.
Examples :
Input : ar1 = [1, 5, 10, 20, 40, 80]
        ar2 = [6, 7, 20, 80, 100]
        ar3 = [3, 4, 15, 20, 30, 70, 80, 120]

Output : [80, 20]

Input : ar1 = [1, 5, 5]
        ar2 = [3, 4, 5, 5, 10]
        ar3 = [5, 5, 10, 20]

Output : [5]

Approach :We have given three arrays, with the help of sets one can easily find out the intersection of these Arrays.
Intersection method simply provides the intersection of both the arrays upon which you want to perform the operation of intersection (or, it simply gives out the common elements in both the array). We will be taking three arrays and then we will take out the intersection.
Below is the implementation of above approach :
# Python3 program to find common elements # in three lists using sets  def IntersecOfSets(arr1, arr2, arr3):    # Converting the arrays into sets    s1 = set(arr1)    s2 = set(arr2)    s3 = set(arr3)          # Calculates intersection of     # sets on s1 and s2    set1 = s1.intersection(s2)         #[80, 20, 100]          # Calculates intersection of sets    # on set1 and s3    result_set = set1.intersection(s3)          # Converts resulting set to list    final_list = list(result_set)    print(final_list)  # Driver Codeif __name__ == '__main__' :          # Elements in Array1    arr1 = [1, 5, 10, 20, 40, 80, 100]          # Elements in Array2    arr2 = [6, 7, 20, 80, 100]          # Elements in Array3    arr3 = [3, 4, 15, 20, 30, 70, 80, 120]          # Calling Function    IntersecOfSets(arr1, arr2, arr3)
Output :
[80, 20]

Python set-programs
python-set
Python
Python Programs
python-set
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python | Finding Solutions of a Polynomial Equation

10 Jun, 2021
Given a quadratic equation, the task is to find the possible solutions to it. Examples:  
Input : 
enter the coef of x2 : 1
enter the coef of x  : 2
enter the constant    : 1
Output :
the value for x is -1.0

Input :
enter the coef of x2 : 2
enter the coef of x  : 3
enter the constant    : 2
Output :
x1 = -3+5.656854249492381i/4 and x2 = -3-5.656854249492381i/4
Algorithm :
Start.
Prompt the values for a, b, c. 
Compute i = b**2-4*a*c
If i get negative value g=square root(-i)
Else h = sqrt(i)
Compute e = -b+h/(2*a)
Compute f = -b-h/(2*a)
If condition e==f then
    Print e
Else
    Print e and f
If i is negative then
    Print -b+g/(2*a) and -b-g/(2*a)
stop
Below is the Python implementation of the above mentioned task.  
Python3
# Python program for solving a quadratic equation.  from math import sqrt  try:         # if user gives non int values it will go to except block    a = 1    b = 2    c = 1    i = b**2-4 * a * c     # magic condition for complex values    g = sqrt(-i)    try:        d = sqrt(i)        # two resultants        e = (-b + d) / 2 * a         f = (-b-d) / 2 * a        if e == f:            print("the values for x is " + str(e))        else:            print("the value for x1 is " + str(e) +                  " and x2 is " + str(f))    except ValueError:        print("the result for your equation is in complex")                 # to print complex resultants.        print("x1 = " + str(-b) + "+" + str(g) + "i/" + str(2 * a) +              " and x2 = " + str(-b) + "-" + str(g) + "i/" +              str(2 * a))           except ValueError:    print("enter a number not a string or char")
Output :  
the values for x is -1.0
Explanation : First, this program will get three inputs from the user. The values are the coefficient of , coefficient of and constant. Then it performs the formula For complex the value of gets negative. Rooting negative values will throw a value error. In this case, turn the result of and then root it. Don’t forget to include at last.  
ruhelaa48
Mathematical
Python
Python Programs
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GATE | GATE-CS-2014-(Set-3) | Question 65

28 Jun, 2021
int getSum(node *root, int L, int H)
{
   // Base Case
   if (root == NULL)
      return 0;

   if (root->key < L)        
       return getSum(root->right, L, H);

  if (root->key > H)
      return getSum(root->left, L, H)

   if (root->key >= L && root->key <=H)        
      return getSum(root->left, L, H) + root->key +
             getSum(root->right, L, H);
}
The above always takes O(m + Logn) time. Note that the code first traverses across height to find the node which lies in range.  Once such a node is found, it recurs for left and right children. Two recursive calls are made only if the node is in range. So for every node that is in range, we make at most one extra call (here extra call means calling for a node that is not in range).Quiz of this Question
GATE-CS-2014-(Set-3)
GATE-GATE-CS-2014-(Set-3)
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
PrintWriter checkError() method in Java with Examples

31 Jan, 2019
The checkError() method of PrintWriter Class in Java is used to check the error state of this PrintWriter instance. This method flushes the stream in order to check the error state. It returns a boolean value that tells if the stream has encountered any error or not.
Syntax:
public boolean checkError()
Parameters: This method do not accepts any parameter.
Return Value: This method returns a boolean value stating whether the Stream has encountered any error or not. It returns true if any error has been encountered. Else it returns false.
Below methods illustrates the working of checkError() method:
Program 1:
// Java program to demonstrate// PrintWriter checkError() method  import java.io.*;  class GFG {    public static void main(String[] args)    {          // The string to be written in the Writer        String str = "GeeksForGeeks";          try {              // Create a PrintWriter instance            PrintWriter writer                = new PrintWriter(System.out);              // Write the above string to this writer            // This will put the string in the stream            // till it is printed on the console            writer.write(str);              // Now check the stream            // using checkError() method            System.out.println("\nHas any error occurred: "                               + writer.checkError());        }        catch (Exception e) {            System.out.println(e);        }    }}
GeeksForGeeks
Has any error occurred: false

Program 2:
// Java program to demonstrate// PrintWriter checkError() method  import java.io.*;  class GFG {    public static void main(String[] args)    {          try {              // Create a PrintWriter instance            PrintWriter writer                = new PrintWriter(System.out);              // Write the char to this writer            // This will put the char in the stream            // till it is printed on the console            writer.write(65);              // Now check the stream            // using checkError() method            System.out.println("\nHas any error occurred: "                               + writer.checkError());        }        catch (Exception e) {            System.out.println(e);        }    }}
A
Has any error occurred: false

Java-Functions
Java-IO package
Java-PrintWriter
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python | Test if element is dictionary value

29 Oct, 2019
Sometimes, while working with Python dictionary, we have a specific use case in which we just need to find if a particular value is present in dictionary as it’s any key’s value. This can have use cases in any field of programming one can think of. Let’s discuss certain ways in which this problem can be solved.
Method #1 : Using loopThis is the brute way in which this problem can be solved. In this, we iterate through the whole dictionary using loops and check for each keys’ value’s for a match using conditional statement.
# Python3 code to demonstrate working of# Test if element is dictionary value# Using loops  # initializing dictionarytest_dict = {'gfg' : 1, 'is' : 2, 'best' : 3}  # printing original dictionaryprint("The original dictionary is : " + str(test_dict))  # Test if element is dictionary value# Using loopsres = Falsefor key in test_dict:    if(test_dict[key] == 3):        res = True         break  # printing resultprint("Is 3 present in dictionary : " + str(res))
The original dictionary is : {'best': 3, 'is': 2, 'gfg': 1}
Is 3 present in dictionary : True

 
Method #2 : Using in operator and values()This task can be performed by utilizing above functionalities. The in operator can be used to get the truth value of presence and values function is required to extract all values of dictionaries.
# Python3 code to demonstrate working of# Test if element is dictionary value# Using in operator and values()  # initializing dictionarytest_dict = {'gfg' : 1, 'is' : 2, 'best' : 3}  # printing original dictionaryprint("The original dictionary is : " + str(test_dict))  # Test if element is dictionary value# Using in operator and values()res = 3 in test_dict.values()  # printing resultprint("Is 3 present in dictionary : " + str(res))
The original dictionary is : {'best': 3, 'is': 2, 'gfg': 1}
Is 3 present in dictionary : True

Python dictionary-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Using a SQL View in SAP BusinessOne

Yes, it is  possible to use a view in Business one client and you can use it too.
 Please find below a sample format that you should be using to query the view in business one environment −
SELECT <Column Names> FROM [dbo].[<View Name>]
I have done the same and it is working for me.
How can we import data from .txt file into MySQL table?

It can be done with the help of LOAD DATA INFILE statement. To illustrate the concept we are having the following data, separated by tab, in ‘A.txt’ whose path is d:/A.txt −
100 John  USA 10000
101 Paul  UK  12000
102 Henry NZ  11000
103 Rick  USA 17000
104 Corey USA 15000
We want to load the data of A.txt into the following table named employee_tbl −
mysql> Create table employee_tbl(Id Int, Name varchar(20), Country Varchar(20),Salary Int);

Query OK, 0 rows affected (0.91 sec)
Now, the transfer of data from a file to a database table can be done with the help of the following table −
mysql> LOAD DATA LOCAL INFILE 'd:\A.txt' INTO table employee_tbl;
Query OK, 5 rows affected (0.15 sec)
Records: 5 Deleted: 0 Skipped: 0 Warnings: 0
 
mysql> Select * from employee_tbl;
+------+-------+---------+--------+
| Id   | Name  | Country | Salary |
+------+-------+---------+--------+
| 100  | John  | USA     |  10000 |
| 101  | Paul  | UK      |  12000 |
| 102  | Henry | NZ      |  11000 |
| 103  | Rick  | USA     |  17000 |
| 104  | Corey | USA     |  15000 |
+------+-------+---------+--------+
5 rows in set (0.00 sec)
The above result set shows that the data from A.txt file has been transferred to the table.