code-rag-bench/online-tutorials huggingface dataset:
readdir() - Unix, Linux System Call

Unix - Home
Unix - Getting Started
Unix - File Management
Unix - Directories
Unix - File Permission
Unix - Environment
Unix - Basic Utilities
Unix - Pipes & Filters
Unix - Processes
Unix - Communication
Unix - The vi Editor
Unix - What is Shell?
Unix - Using Variables
Unix - Special Variables
Unix - Using Arrays
Unix - Basic Operators
Unix - Decision Making
Unix - Shell Loops
Unix - Loop Control
Unix - Shell Substitutions
Unix - Quoting Mechanisms
Unix - IO Redirections
Unix - Shell Functions
Unix - Manpage Help
Unix - Regular Expressions
Unix - File System Basics
Unix - User Administration
Unix - System Performance
Unix - System Logging
Unix - Signals and Traps
Unix - Useful Commands
Unix - Quick Guide
Unix - Builtin Functions
Unix - System Calls
Unix - Commands List
Unix Useful Resources
Computer Glossary
Who is Who
Copyright © 2014 by tutorialspoint
#include <linux/types.h> 
#include <linux/dirent.h> 

int readdir(unsigned int fd, struct dirent *dirp, 
            unsigned int count); 


int readdir(unsigned int fd, struct dirent *dirp, 
            unsigned int count); 


readdir() reads one
dirent structure from the directory
pointed at by
fd into the memory area pointed to by
dirp. The parameter
count is ignored; at most one dirent structure is read.


The
dirent structure is declared as follows:



struct dirent
{
    long d_ino;                 /* inode number */
    off_t d_off;                /* offset to this dirent */
    unsigned short d_reclen;    /* length of this d_name */
    char d_name [NAME_MAX+1];   /* filename (null-terminated) */
}


d_ino is an inode number.
d_off is the distance from the start of the directory to this
dirent. d_reclen is the size of
d_name, not counting the null terminator.
d_name is a null-terminated filename.
How to Download & Install NLTK on Windows?

16 Dec, 2021
NLTK is Natural Language Tool Kit. It is used to build python programming. It helps to work with human languages data. It gives a very easy user interface. It supports classification, steaming, tagging, etc.
In windows, we first have to install the python current version. Then we have to install pip with it. Without pip, NLTK can not be installed.
Step 1: Browse to the official site of python by clicking this link.
Step 2: Move the cursor to the Download button & then click on the latest python version.
Step 3: Open the downloaded file. Click on the checkbox & Click on Customize installation.
Step 4: Click on Next.
Step 5: Click on Install.
Step 6: Wait till installation finish.
Step 7: Click on Close.
Step 8: Open Command Prompt & execute the following commands:
python --version
pip --version
pip install nltk
Hence, NLTK installation will start.
Step 9: Then you can see the successfully installed message.
Hence NLTK installation is successful
how-to-install
Picked
How To
Installation Guide
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Introduction to Processing | Java

07 May, 2020
Processing is an open-source low level animation and GUI library built on Java with additional simplifications like additional classes, aliased mathematical functions and operations. It also provides a GUI for simple compilation of the programs written in processing.
Features of Processing: The following are the features of processing:
It includes a sketchbook which is a minimalistic alternative to an IDE. This sketchbook can be used as a normal IDE to organize projects.
Every sketch drawn in processing is a subclass of the Java class(PApplet). This class implements almost all the features of processing.
Since processing inherits the properties of the class, all the additional classes defined in the sketch will be treated as an inner class when the code is being converted into a pure java code before compiling. Therefore, the use of static variables and methods is strictly prohibited in processing.
The processing language also gives the users an option to create own classes in the PApplet sketch. Therefore, this gives the users a chance to use a more complex data structures apart from the basic data types in java.
Installing Processing: In order to code in the processing language, the users can either download processing sketchbook from the official website. Apart from that, the users can also download the code jar file and set it up in any of the IDE to use processing.
Example: The following is an example to get an understanding of how to code in processing. Let’s see how to draw a circle in processing. In order to do this, we need to learn about the main function that processing invokes from its library. That means, we only have to define this function but not invoke it.
Below is a sample processing code which draws a circle:
// This function is called whenever we// start the app.void setup(){    // This function is a built in function    // in processing which takes two    // arguments: width and height    // 400, 400 means a window of    // length 400 pixels and width    // 400 pixels    size(400, 400);}  // This function is called once per// frame. That is, if the frame rate// is 60, then this will be called// 60 times in one secondvoid draw(){      // This is also an inbuilt function    // which can take 4, 3 or 1 argument    // where each argument represents the    // intensity of each colour like:    // 4 = (red, green, blue alpha)    // 3 = (red, green, blue)    // 1 = (gray_scale_value)    background(0);      // This command draws the circle    // on our canvas at x=width/2,    // y=height/2, diameter=200    circle(width / 2, height / 2, 200);}
Output: The output for the above program is:
Algorithms
Java
Java
Algorithms
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
PostgreSQL – SELECT INTO

28 Aug, 2020
In PostgreSQL, the SELECT INTO statement allows users to create a new table and inserts data returned by a query. The new table columns have names and data types linked with the output columns of the SELECT clause. Unlike the SELECT statement, the SELECT INTO statement does not return data to the client.
Syntax:
SELECT
    column_list 
INTO [ TEMPORARY | TEMP | UNLOGGED ] [ TABLE ] new_table_name
FROM
    table_name
WHERE
    condition;
In the process of creating a new table with the structure and data derived from a query result set, one has to specify the new table name in the INTO clause. The TEMP or TEMPORARY keyword is optional; it allows users to create a temporary table instead.The WHERE clause allows users to specify the data from the original tables that should be inserted into the new table. Besides the WHERE clause, one can use other clauses in the SELECT statement for the SELECT INTO statement such as INNER JOIN, LEFT JOIN, GROUP BY, and HAVING.
Now let’s look into some examples.For examples we will be using the sample database (ie, dvdrental).
Example 1:In this example, we will use the film table from the dvdrental database to create a new table named film_r that contains all films with the rating of R and has a 5-day rental duration using the below statement:
SELECT
    film_id,
    title,
    rental_rate
INTO TABLE film_r
FROM
    film
WHERE
    rating = 'R'
AND rental_duration = 5
ORDER BY
    title;
Now we can verify the created table using the below statement:
SELECT
    *
FROM
    film_r;
Output:
Example 2:In this example, we create a temporary table named short_film that has all films whose lengths are under 60 minutes using the below statement:
SELECT
    film_id,
    title,
    length 
INTO TEMP TABLE short_film
FROM
    film
WHERE
    length < 60
ORDER BY
    title;
Now we verify the table short_film using the below statement:
SELECT
    *
FROM
    short_film;
Output:
Note: One cannot use the SELECT INTO statement in PL/pgSQL or ECPG because they interpret the INTO clause differently. In this case, you can use the CREATE TABLE AS statement which provides more functionality than the SELECT INTO statement.
postgreSQL-basics
PostgreSQL
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
Nested Decorators in Python

25 Aug, 2021
Everything in Python is an object. Even function is a type of object in Python. Decorators are a special type of function which return a wrapper function. They are considered very powerful in Python and are used to modify the behaviour of a function temporarily without changing its actual value. 
Nesting means placing or storing inside the other. Therefore, Nested Decorators means applying more than one decorator inside a function. Python allows us to implement more than one decorator to a function. It makes decorators useful for reusable building blocks as it accumulates the several effects together.
A function can be decorated multiple times. We need to define the decorator first that we want to wrap the output string with, and then apply them to the function using the ‘@’ . One simply needs to place the decorators above the desired function.
Syntax :
@function1
@function2
def function(name):
      print(f"{name}")
Nested decorators follow a bottom to top approach i.e the reverse order. It can be related to a construction of  building where we start the construction from the bottom (the ground) and then start building the floors.
Example :
Python3
# Python program to demonstrate# nested decorators def italic(func):         def wrapper():        return '<i>' + func() + '</i>'         return wrapper def strong(func):         def wrapper():        return '<strong>' + func() + '</strong>'         return wrapper  @italic@strongdef introduction():    return 'This is a basic program' print(introduction())
Output:
<i><strong>This is a basic program</strong></i>
Explanation :
We have defined two decorators first, which are used in wrapping the output string of the decorated function in the ‘strong’ and ‘italic’ tags of HTML.Then we are applying the two decorators to our ‘introduction’ function by using just an “@” and the function name. For example in this program we are using @italic and @strong.The hierarchy that it follows is from bottom to top. Therefore according to it the string is wrapped with ‘strong’ first an then with ‘italic’.
We have defined two decorators first, which are used in wrapping the output string of the decorated function in the ‘strong’ and ‘italic’ tags of HTML.
Then we are applying the two decorators to our ‘introduction’ function by using just an “@” and the function name. For example in this program we are using @italic and @strong.
The hierarchy that it follows is from bottom to top. Therefore according to it the string is wrapped with ‘strong’ first an then with ‘italic’.
surinderdawra388
simmytarika5
Python Decorators
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
Iterate over a list in Python
Python Classes and Objects
Convert integer to string in Python
numpy.finfo() function – Python

18 Jun, 2020
numpy.finfo() function shows machine limits for floating point types.
Syntax : numpy.finfo(dtype)
Parameters :dtype : [float, dtype, or instance] Kind of floating point data-type about which to get information.Return : Machine parameters for floating point types.
Code #1 :
# Python program explaining# numpy.finfo() function           # importing numpy as geek import numpy as geek        gfg = geek.finfo(geek.float32)     print (gfg)
Output :
Machine parameters for float32
---------------------------------------------------------------
precision =   6   resolution = 1.0000000e-06
machep =    -23   eps =        1.1920929e-07
negep =     -24   epsneg =     5.9604645e-08
minexp =   -126   tiny =       1.1754944e-38
maxexp =    128   max =        3.4028235e+38
nexp =        8   min =        -max
---------------------------------------------------------------

 Code #2 :
# Python program explaining# numpy.finfo() function           # importing numpy as geek import numpy as geek        gfg = geek.finfo(geek.float64)     print (gfg)
Output :
Machine parameters for float64
---------------------------------------------------------------
precision =  15   resolution = 1.0000000000000001e-15
machep =    -52   eps =        2.2204460492503131e-16
negep =     -53   epsneg =     1.1102230246251565e-16
minexp =  -1022   tiny =       2.2250738585072014e-308
maxexp =   1024   max =        1.7976931348623157e+308
nexp =       11   min =        -max
---------------------------------------------------------------

Python-numpy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to select rows of an R data frame that are non-NA?

To select rows of an R data frame that are non-Na, we can use complete.cases function with single square brackets. For example, if we have a data frame called that contains some missing values (NA) then the selection of rows that are non-NA can be done by using the command df[complete.cases(df),].
Consider the below data frame −
Live Demo
> x1<-sample(c(1,NA),20,replace=TRUE)
> x2<-sample(c(5,NA),20,replace=TRUE)
> x3<-sample(c(3,NA),20,replace=TRUE)
> df1<-data.frame(x1,x2,x3)
> df1
   x1 x2 x3
1   1 NA NA
2  NA  5  3
3   1  5 NA
4   1 NA NA
5  NA  5 NA
6  NA  5  3
7  NA  5 NA
8   1 NA  3
9  NA  5 NA
10 NA  5 NA
11 NA NA NA
12  1  5  3
13 NA  5  3
14 NA NA NA
15  1 NA NA
16 NA  5  3
17 NA NA  3
18 NA NA NA
19  1 NA  3
20 NA NA  3
   x1 x2 x3
1   1 NA NA
2  NA  5  3
3   1  5 NA
4   1 NA NA
5  NA  5 NA
6  NA  5  3
7  NA  5 NA
8   1 NA  3
9  NA  5 NA
10 NA  5 NA
11 NA NA NA
12  1  5  3
13 NA  5  3
14 NA NA NA
15  1 NA NA
16 NA  5  3
17 NA NA  3
18 NA NA NA
19  1 NA  3
20 NA NA  3
Selecting rows of df1 that do not contain any NA −
> df1[complete.cases(df1),]
   x1 x2 x3
12  1  5  3
   x1 x2 x3
12  1  5  3
Live Demo
> y1<-sample(c(rnorm(2),NA),20,replace=TRUE)
> y2<-sample(c(rnorm(2),NA),20,replace=TRUE)
> df2<-data.frame(y1,y2)
> df2
           y1        y2
1  0.15079115 -0.626630
2  0.15079115        NA
3          NA -0.626630
4  0.15079115 -0.626630
5  0.15079115        NA
6  0.15079115 -0.626630
7  0.15079115        NA
8  0.15079115 -1.691553
9          NA -1.691553
10         NA -0.626630
11 0.15079115 -1.691553
12 0.15079115        NA
13         NA -1.691553
14         NA -1.691553
15 0.15079115 -1.691553
16         NA -0.626630
17 0.01495388 -0.626630
18 0.01495388 -1.691553
19 0.15079115 -1.691553
20         NA        NA
Selecting rows of df2 that do not contain any NA −
> df2[complete.cases(df2),]
           y1        y2
1  0.15079115 -0.626630
4  0.15079115 -0.626630
6  0.15079115 -0.626630
8  0.15079115 -1.691553
11 0.15079115 -1.691553
15 0.15079115 -1.691553
17 0.01495388 -0.626630
18 0.01495388 -1.691553
19 0.15079115 -1.691553
Live Demo
> z1<-sample(c("A",NA),20,replace=TRUE)
> z2<-sample(c("B",NA),20,replace=TRUE)
> z3<-sample(c("C",NA),20,replace=TRUE)
> df3<-data.frame(z1,z2,z3)
> df3
     z1   z2   z3
1     A <NA>    C
2  <NA>    B    C
3  <NA> <NA> <NA>
4     A    B <NA>
5  <NA> <NA>    C
6     A <NA>    C
7     A    B    C
8  <NA>    B    C
9  <NA> <NA>    C
10 <NA> <NA>    C
11    A <NA>    C
12 <NA> <NA>    C
13    A    B    C
14    A    B    C
15 <NA> <NA> <NA>
16    A    B    C
17 <NA> <NA> <NA>
18 <NA> <NA>    C
19    A    B    C
20 <NA> <NA> <NA>
Selecting rows of df3 that do not contain any NA −
> df3[complete.cases(df3),]
   z1 z2 z3
7   A  B  C
13  A  B  C
14  A  B  C
16  A  B  C
19  A  B  C
Wildcard matching of string JavaScript

We are required to write a JavaScript function that accepts two strings and a number n. The
function matches the two strings i.e., it checks if the two strings contains the same characters.
The function should return true if both the strings contain the same character irrespective of
their order or if they contain at most n different characters, otherwise the function should return
false.
Let's write the code for this function −
const str1 = 'first string';
const str2 = 'second string';
const wildcardMatching = (first, second, num) => {
   let count = 0;
   for(let i = 0; i < first.length; i++){
      if(!second.includes(first[i])){
         count++;
      };
      if(count > num){
         return false;
      };
   };
   return true;
};
console.log(wildcardMatching(str1, str2, 2));
console.log(wildcardMatching(str1, str2, 1));
console.log(wildcardMatching(str1, str2, 0));
The output in the console will be −
true
true
false
Change Cursor Color with CSS caret-color

For changing the color of insertion caret, CSS caret-color property is used.
The following examples illustrate the CSS caret-color property.
 Live Demo
<!DOCTYPE html>
<html>
<head>
<style>
form {
   padding: 2%;
   margin: 2%;
   text-align: center;
}
form:focus-within {
   box-shadow: 0 0 10px rgba(0,0,0,0.6);
   background-color: beige;
}
input {
   font-size: 3em;
   caret-color: chartreuse;
   margin: 2%;
}
</style>
</head>
<body>
<form>
<input value="Check the caret color!" />
<button>Hit!</button>
</form>
</body>
</html>
This will produce the following result −
 Live Demo
<!DOCTYPE html>
<html>
<head>
<style>
form {
   padding: 2%;
   margin: 2%;
   background-color: thistle;
}
form:focus-within {
   box-shadow: 0 0 10px rgba(0,0,0,0.6);
}
textarea {
   caret-color: transparent;
}
</style>
</head>
<body>
<form>
<input type="radio" />1
<input type="radio" />2
<textarea placeholder="Invisible"></textarea>
</form>
</body>
</html>
This will produce the following result −
How to select the maximum value of a column in MySQL?

You can use ORDER BY clause or aggregate function MAX() to select the maximum value.
Following is the syntax −
select yourColumnName from yourTableName order by yourColumnName desc limit 0,1;
Let us first create a table −
mysql> create table DemoTable
   (
   Number int
   );
Query OK, 0 rows affected (0.52 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values(790);
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable values(746);
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values(480);
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable values(880);
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable values(879);
Query OK, 1 row affected (0.20 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+--------+
| Number |
+--------+
| 790    |
| 746    |
| 480    |
| 880    |
| 879    |
+--------+
5 rows in set (0.00 sec)
Following is the query to select the maximum value of a column in MySQL −
mysql> select Number from DemoTable order by Number desc limit 0,1;
This will produce the following output −
+--------+
| Number |
+--------+
| 880    |
+--------+
1 row in set (0.00 sec)
You can also use aggregate function MAX() for this −
mysql> select MAX(Number) from DemoTable;
This will produce the following output −
+-------------+
| MAX(Number) |
+-------------+
| 880         |
+-------------+
1 row in set (0.00 sec)
Recovering Lost Commits in Git - GeeksforGeeks

10 May, 2020
Git is a very powerful tool, and with great power comes great responsibilities. If not used and handles properly, It might cause you to lose your commits. There might be situations when you may find all of your work missing at once.
If you have regularly committed your work, there is a way to recover these lost commits.This tutorial will aim at using the
 git reflog
and the
git cherry-pick
commands to recover your lost commits in Git.
Note: Using the reflog will only work for a certain amount of time after the commits are lost. Git cleans the reflog periodically, so don’t wait too long!
The first step to recovering your lost commits is to recover the list of all your previous commits and actions done on the repository.
Note: Keep in mind that the given commit hashes and signatures may differ from that of your local repository. Replace all relevant information with the info corresponding to your log.
Run this command
git reflog
After running the command this is what you will see as the output.
$ git reflog
c9f9669 HEAD@{0}: commit: Fixed test cases to run on Unix
b3ca8a4 HEAD@{1}: pull: Fast-forward
54ba188 HEAD@{2}: pull origin master: Fast-forward
e659a21 HEAD@{3}: reset: moving to HEAD~1
12944d8 HEAD@{4}: reset: moving to HEAD~1
6f40152 HEAD@{5}: reset: moving to HEAD~1
3de61ba HEAD@{6}: pull: Fast-forward
e659a21 HEAD@{7}: reset: moving to HEAD^1
12944d8 HEAD@{8}: reset: moving to HEAD^1
6f40152 HEAD@{9}: reset: moving to HEAD^1
3de61ba HEAD@{10}: commit: Removed Query object   
6f40152 HEAD@{11}: pull: Merge made by the 'recursive' strategy.
12944d8 HEAD@{12}: commit: API touchups   --- We want to recover this commit.
e659a21 HEAD@{13}: commit: Test enhancements
07419e1 HEAD@{14}: pull: Fast-forward

Find of the Hash of the commit you want to recover, For ex-12944d8.Now use the following command to bring your lost commit back.
 git cherry-pick 12944d8 
That’s it! Your work should be recovered soon with the following success commands:
Finished one cherry-pick.
[master 12944d8] API touchups
3 files changed, 36 insertions(+), 3 deletions(-)

If there is a merge conflict, the following message will show up.
error: could not apply 12944d8... API touchups
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add ' or 'git rm '
hint: and commit the result with 'git commit'

using the git status command can help you identify what has to be done.
Picked
Git
Write From Home
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Set Git Username and Password in GitBash?
Difference Between Git Push Origin and Git Push Origin Master
How to Undo a Commit in Git ?
How to Push Git Branch to Remote?
Deleting a Local GitHub Repository
Convert integer to string in Python
Convert string to integer in Python
How to set input type date in dd-mm-yyyy format using HTML ?
Python infinity
Matplotlib.pyplot.title() in Python
Filter column value by the first character in MySQL

You can use LEFT() from MySQL. Let us first create a −
mysql> create table DemoTable1428
   -> (
   -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> EmployeeName varchar(20)
   -> );
Query OK, 0 rows affected (1.05 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1428(EmployeeName) values('Chris Brown');
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable1428(EmployeeName) values('Bob Brown');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable1428(EmployeeName) values('John Smith');
Query OK, 1 row affected (0.23 sec)
mysql> insert into DemoTable1428(EmployeeName) values('David Miller');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable1428(EmployeeName) values('John Doe');
Query OK, 1 row affected (0.22 sec)
mysql> insert into DemoTable1428(EmployeeName) values('Carol Johnson');
Query OK, 1 row affected (0.16 sec)
Display all records from the table using select −
mysql> select * from DemoTable1428;
This will produce the following output −
+------------+---------------+
| EmployeeId | EmployeeName  |
+------------+---------------+
|          1 | Chris Brown   |
|          2 | Bob Brown     |
|          3 | John Smith    |
|          4 | David Miller  |
|          5 | John Doe      |
|          6 | Carol Johnson |
+------------+---------------+
6 rows in set (0.00 sec)
Following is the query to filter column value by the first character −
mysql> select * from DemoTable1428 where left(EmployeeName,1)='J';
This will produce the following output −
+------------+--------------+
| EmployeeId | EmployeeName |
+------------+--------------+
|          3 | John Smith   |
|          5 | John Doe     |
+------------+--------------+
2 rows in set (0.00 sec)
How to Get the Number of Elements in a Python List?

01 Jul, 2022
In this article, we will discuss how do we get the number of elements in a list in Python.
Input: [1,2,3,4,5]
Output:No of elements in the list are 5
Input: [1.2 ,4.5, 2.2]  
Output:No of elements in the list are 3 
Input: [“apple”, “banana”, “mangoe”]
Output:No of elements in the list are 3
Before getting the Number of Elements in the Python List we have to create an empty List. After creating an empty list we have to insert the items or elements into the list. 
There are three methods to get the number of elements in the list i.e,
Using Len( ) function
Using for loop 
Using length_hint
We can use the len function i.e len( ) to return the number of elements present in the list
Python3
# Returning the number of elements using# len() function in python list = []  # declare empty list# adding items or elements to the listlist.append(1)list.append(2)list.append(3)list.append(4) # printing the listprint(list) # using the len() which return the number# of elements in the listprint("No of elements in list are")print(len(list))
[1, 2, 3, 4]
No of elements in list are
4
We can declare a counter variable to count the number of elements in the list using a for loop and print the counter after the loop in python gets terminated. 
Python3
# Python Program for returning the number# of elements in the list using for loop list = []  # declaring empty list # inserting elements in the list using# append methodlist.append(1)list.append(2)list.append(3)list.append(4) # declaring count variable as integer to keep# track of the number of elements in for loopcount = 0 # for loop for iterating through each element# in the listfor i in list:     # increments count variable for each    # iteration    count = count+1 # prints the count variable i.e the total number# of elements in the listprint(list) print("No of elements in the list are")print(count)
[1, 2, 3, 4]
No of elements in the list are
4
Python3
from operator import length_hint l = [1, 2, 3, 4]length_hint(l)
Output:
4
Hence, in this way, we can return the number of elements of a list in python using for loop.
simmytarika5
surindertarika1234
surajkumarguptaintern
Picked
Python list-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to 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 | Convert string dictionary to dictionary
Python Program for Fibonacci numbers
Python | Pandas Series.str.findall()

28 Sep, 2018
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Pandas str.findall() method is also used to find substrings or separators in each string in a series. But it is different from str.find() method. Instead of returning the index, it returns list with substrings and size of list is number of times it occurred.
Syntax: Series.str.findall(pat, flags=0)
Parameters:pat: Substring to be searched forflags: Regex flags that can be passed (A, S, L, M, I, X), default is 0 which means None. For this regex module (re) has to be imported too.
Return Type: Series of list(strings).
To download the CSV used in code, click here.In the following examples, the data frame used contains data of some NBA players. The image of data frame before any operations is attached below.
Example #1: Searching character in string
In this example, the name column is searched for ‘r’ using str.findall() method and output is stored in new column. Before doing any operations, null rows are dropped using .dropna() to avoid errors.
# importing pandas module import pandas as pd     # making data frame data = pd.read_csv("https://media.geeksforgeeks.org/wp-content/uploads/nba.csv")     # removing null values to avoid errors data.dropna(inplace = True)   # string to be searched forsearch ='r'  # returning values and creating columndata["Findall(name)"]= data["Name"].str.findall(search)  # displaydata.head(10)
Output:As shown in the output image, it can be compared that the number of ‘e’ returned is equal to number of time it occurred in string. Example #2: Searching character and passing IGNORECASE flag
In this example, the Name column is searched for ‘a’ and the IGNORECASE flag is passed. For that re module has to be imported too. The returned series from str.findall() method is stored in a New column.
# importing pandas module import pandas as pd   # importing regex moduleimport re    # making data frame data = pd.read_csv("https://media.geeksforgeeks.org/wp-content/uploads/nba.csv")     # removing null values to avoid errors data.dropna(inplace = True)   # string to be searched forsearch ='a'  # returning values and creating columndata["Findall(name)"]= data["Name"].str.findall(search, flags = re.I)  # displaydata.head(10)
Output:As shown in the output image, it can be seen in the first row itself that both ‘A’ and ‘a’ were returned since IGNORECASE flag(re.I) was passed.
Python pandas-series
Python pandas-series-methods
Python-pandas
Python-pandas-series-str
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Different ways to create Pandas Dataframe
Enumerate() in Python
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Python Classes and Objects
Convert integer to string in Python
Python | os.path.join() method
Introduction To PYTHON
Python | Difference Between List and Tuple

17 Mar, 2021
List and Tuple in Python are the class of data structure. The list is dynamic, whereas the tuple has static characteristics. List is just like the arrays, declared in other languages. Lists need not be homogeneous always which makes it the most powerful tool in Python. In Python, the list is a type of container in Data Structures, which is used to store multiple data at the same time. Lists are a useful tool for preserving a sequence of data and further iterating over it. Syntax: 
list_data = ['an', 'example', 'of', 'a', 'list']
Tuple is also a sequence data type that can contain elements of different data types, but these are immutable in nature. In other words, a tuple is a collection of Python objects separated by commas. The tuple is faster than the list because of static in nature. Syntax:  
tuple_data = ('this', 'is', 'an', 'example', 'of', 'tuple')
Difference Between List and Tuple in Python:  
 
shivam2608
Difference Between
Python
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
Difference Between Method Overloading and Method Overriding in Java
Differences between JDK, JRE and JVM
Stack vs Heap Memory Allocation
Difference between Clustered and Non-clustered index
Read JSON file using Python
Adding new column to existing DataFrame in Pandas
Python map() function
How to get column names in Pandas dataframe
Different ways to create Pandas Dataframe
Python – Vertical Concatenation in Matrix

30 Aug, 2020
Given a String Matrix, perform column-wise concatenation of strings, handling variable lists lengths.
Input : [[“Gfg”, “good”], [“is”, “for”]]Output : [‘Gfgis’, ‘goodfor’]Explanation : Column wise concatenated Strings, “Gfg” concatenated with “is”, and so on.
Input : [[“Gfg”, “good”, “geeks”], [“is”, “for”, “best”]]Output : [‘Gfgis’, ‘goodfor’, “geeksbest”]Explanation : Column wise concatenated Strings, “Gfg” concatenated with “is”, and so on.
Method #1 : Using loop
This is brute way in which this task can be performed. In this, we iterate for all the columns and perform concatenation. 
Python3
# Python3 code to demonstrate working of # Vertical Concatenation in Matrix# Using loop  # initializing liststest_list = [["Gfg", "good"], ["is", "for"], ["Best"]]  # printing original listprint("The original list : " + str(test_list))  # using loop for iterationres = []N = 0while N != len(test_list):    temp = ''    for idx in test_list:                  # checking for valid index / column        try: temp = temp + idx[N]        except IndexError: pass    res.append(temp)    N = N + 1  res = [ele for ele in res if ele]  # printing result print("List after column Concatenation : " + str(res))
The original list : [['Gfg', 'good'], ['is', 'for'], ['Best']]
List after column Concatenation : ['GfgisBest', 'goodfor']

Method #2 : Using join() + list comprehension + zip_longest()
The combination of above functions can be used to solve this problem. In this, we handle the null index values using zip_longest, and join() is used to perform task of concatenation. The list comprehension drives one-liner logic.
Python3
# Python3 code to demonstrate working of # Vertical Concatenation in Matrix# Using join() + list comprehension + zip_longest()from itertools import zip_longest  # initializing liststest_list = [["Gfg", "good"], ["is", "for"], ["Best"]]  # printing original listprint("The original list : " + str(test_list))  # using join to concaternate, zip_longest filling values using # "fill"res = ["".join(ele) for ele in zip_longest(*test_list, fillvalue ="")]  # printing result print("List after column Concatenation : " + str(res))
The original list : [['Gfg', 'good'], ['is', 'for'], ['Best']]
List after column Concatenation : ['GfgisBest', 'goodfor']

Python list-programs
Python string-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
Read a file line by line in Python
Python String | replace()
Python program to convert a list to string
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Python | Convert string dictionary to dictionary
jQuery data() with Examples

The data() method in jQuery is used to attach data to or gets data from selected elements.
The syntax is as follows −
$(selector).data(name)
$(selector).data(name,value)
Above, the name is the name of data to retrieve for the 1st syntax.
For the 2nd syntax, the name is the name of data to set, whereas value is the value of data to set.
Let us now see an example to implement the jQuery data() method −
 Live Demo
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $(".button1").click(function(){
         $("div").data("student", "Jack Sparrow");
         alert("Student Name = " +$("div").data("student"));
      });
      $(".button2").click(function(){
         $("div").removeData("student");
         alert("Student Name = " +$("div").data("Jack Sparrow"));
      });
   });
</script>
<style>
.button1 {
   background-color: orange;
   color: white;
}
.button2 {
   background-color: orange;
   color: white;
}
</style>
</head>
<body>
<h2>Demo Heading</h2>
<button class="button1">Attach</button><br><br>
<button class="button2">Remove</button>
<div></div>
</body>
</html>
This will produce the following output −
Python | Tail Sliced List Summation

10 Oct, 2021
We often come to the situations in which we need to decrease the size of the list by truncating the last elements of the list and perform remaining list summation. This particular problem occurs when we need to optimize memory. This has its application in the day-day programming when sometimes we require to get all the lists of similar size. Let’s discuss certain ways in which this task can be performed.Method #1 : Using len() + list slicing + sum() List slicing can perform this particular task in which we just slice the first len(list) – K elements to be in the list and hence removing the last K elements. The task of performing tail summation is performed using sum(). 
Python3
# Python code to demonstrate# Tail Sliced List Summation# using len() + list slicing + sum() # initializing listtest_list = [1, 4, 6, 3, 5, 8] # printing original listprint ("The original list is : " + str(test_list)) # initializing KK = 3 # using len() + list slicing + sum()# Tail Sliced List Summationres = sum(test_list[: len(test_list) - K]) # printing resultprint ("The tail removed list summation : " + str(res))
The original list is : [1, 4, 6, 3, 5, 8]
The tail removed list summation : 11
 
 Method #2 : Using Negative list slicing + sum() We can perform this particular task using the negative list slicing in which we start removing the elements from the last index of the list and hence remove all the K elements from the last. We remove None if 0 elements are asked to be removed. The task of performing tail summation is performed using sum(). 
Python3
# Python code to demonstrate# Tail Sliced List Summation# using negative list slicing + sum() # initializing listtest_list = [1, 4, 6, 3, 5, 8] # printing original listprint ("The original list is : " + str(test_list)) # initializing KK = 3 # using negative list slicing + sum()# Tail Sliced List Summationres = sum(test_list[: -K or None]) # printing resultprint ("The tail removed list summation : " + str(res))
The original list is : [1, 4, 6, 3, 5, 8]
The tail removed list summation : 11
 
simmytarika5
Python list-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
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
Tailwind CSS Min-Height

23 Mar, 2022
This class accepts lots of values in tailwind CSS in which all the properties are covered in class form.  It is the alternative to the CSS Min-Height Property. This class is used to set the minimum height of an element. The min-height class is used when the content of the element is smaller than the min-height and if the content is larger than the min-height, it has no effect. This class ensures that the value of the height class is not less than the specified min-height value of the element in consideration.
Min-Height classes:
min-h-0
min-h-full
min-h-screen
min-h-0: This class is used to set the minimum specific height for any element.
Syntax:
<element class="min-h-0">...</element>
Example:
HTML
<!DOCTYPE html> <head>     <link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"           rel="stylesheet"> </head>   <body class="text-center mx-4 space-y-2">     <h1 class="text-green-600 text-5xl font-bold">        GeeksforGeeks    </h1>     <b>Tailwind CSS Min-Height Class</b>     <div class="mx-48 bg-green-200 p-8">        <div class="min-h-0 bg-green-400                     rounded-lg">min-h-0</div>    </div></body>   </html>
Output:
min-h-full: This class is used to set the minimum height of an element that is full, depending on the parent element.
Syntax:
<element class="min-h-full">...</element>
Example:
HTML
<!DOCTYPE html> <head>     <link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"           rel="stylesheet"> </head>   <body class="text-center mx-4 space-y-2">     <h1 class="text-green-600 text-5xl font-bold">        GeeksforGeeks    </h1>     <b>Tailwind CSS Min-Height Class</b>     <div class="mx-48 h-48 bg-green-200 p-8">        <div class="min-h-full bg-green-400                     rounded-lg">min-h-full</div>    </div></body>   </html>
Output:
min-h-screen: This class is used to make an element span the entire height of the viewport minimum.
Syntax:
<element class="min-h-screen">...</element>
Example:
HTML
<!DOCTYPE html> <head>     <link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"           rel="stylesheet"> </head>   <body class="text-center mx-4 space-y-2">     <h1 class="text-green-600 text-5xl font-bold">        GeeksforGeeks    </h1>     <b>Tailwind CSS Min-Height Class</b>     <div class="mx-48 bg-green-200 p-8">        <div class="min-h-screen bg-green-400                     rounded-lg">min-h-screen</div>    </div></body>   </html>
Output:
Tailwind CSS
Tailwind-Sizing
CSS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Java Generics - Parameterized Types

A Generic class can have parameterized types where a type parameter can be substituted with a parameterized type. Following example will showcase above mentioned concept.
Create the following java program using any editor of your choice.
GenericsTester.java
package com.tutorialspoint;

import java.util.ArrayList;
import java.util.List;


public class GenericsTester {
   public static void main(String[] args) {
      Box<Integer, List<String>> box
         = new Box<Integer, List<String>>();
      
      List<String> messages = new ArrayList<String>();
      
      messages.add("Hi");
      messages.add("Hello");
      messages.add("Bye");      
      
      box.add(Integer.valueOf(10),messages);
      System.out.printf("Integer Value :%d\n", box.getFirst());
      System.out.printf("String Value :%s\n", box.getSecond());

      
   }
}

class Box<T, S> {
   private T t;
   private S s;

   public void add(T t, S s) {
      this.t = t;
      this.s = s;
   }

   public T getFirst() {
      return t;
   } 

   public S getSecond() {
      return s;
   } 
}
This will produce the following result.
Integer Value :10
String Value :[Hi, Hello, Bye]


    16 Lectures 
     2 hours 

 Malhar Lathkar

    19 Lectures 
     5 hours 

 Malhar Lathkar

    25 Lectures 
     2.5 hours 

 Anadi Sharma

    126 Lectures 
     7 hours 

  Tushar Kale

    119 Lectures 
     17.5 hours 

 Monica Mittal

    76 Lectures 
     7 hours 

 Arnab Chakraborty
 Print
 Add Notes
 Bookmark this page
Count numbers in range 1 to N which are divisible by X but not by Y in C++

We are provided a number N. The goal is to find the numbers that are divisible by X and not by Y and are in the range [1,N].
Let’s understand with examples.
Input 
N=20 X=5 Y=20
Output 
Numbers from 1 to N divisible by X not Y: 2
Explanation 
Only 5 and 15 are divisible by 5 and not 10.
Input 
N=20 X=4 Y=7
Output 
Numbers from 1 to N divisible by X not Y: 5
Explanation 
Numbers 4, 8, 12, 16 and 20 are divisible by 4 and not 7.
We take an integer N.
We take an integer N.
Function divisibleXY(int x, int y, int n) returns a count of numbers from 1 to N which are divisible by X and not Y.
Function divisibleXY(int x, int y, int n) returns a count of numbers from 1 to N which are divisible by X and not Y.
Take the initial variable count as 0 for such numbers.
Take the initial variable count as 0 for such numbers.
Traverse range of numbers using for loop. i=1 to i=n
Traverse range of numbers using for loop. i=1 to i=n
Now for each number i, check if ( i%x==0 && i%y!=0 ), if true increment count.
Now for each number i, check if ( i%x==0 && i%y!=0 ), if true increment count.
Return the count as result.
Return the count as result.
 Live Demo
#include <bits/stdc++.h>
using namespace std;
int divisibleXY(int x, int y, int n){
   int count = 0;
   for (int i = 1; i <= n; i++) {
      if(i%x==0 && i%y!=0 )
         { count++; }
   }
   return count;
}
int main(){
   int N = 100;
   int X=6, Y=8;
   cout <<"Numbers from 1 to N which are divisible by X and not Y: "<< divisibleXY(X,Y,N);
   return 0;
}
If we run the above code it will generate the following output −
Numbers from 1 to N which are divisible by X and not Y: 12
Java program to swap two integers

Read integers from users using the nextInt() method of the Scanner class.
To swap them −
Create a variable (temp), initialize it with 0.
Assign 1st number to temp.
Assign 2nd number to 1st number.
Assign temp to second number.
import java.util.Scanner;
public class SwapTwoNumbers {
   public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter first number :: ");
      int num1 = sc.nextInt();
      System.out.println("Enter second number :: ");
      int num2 = sc.nextInt();

      int temp = 0;
      temp = num1;
      num1 = num2;
      num2 = temp;

      System.out.println("After swapping ::");
      System.out.println("Value of first number ::"+ num1);
      System.out.println("Value of first number ::"+ num2);
   }
}
Enter first number ::
22
Enter second number ::
33
After swapping ::
Value of first number ::33
Value of first number ::22
Difference between Direct and Indirect Addressing Modes - GeeksforGeeks

04 May, 2020
Prerequisite: Addressing Modes
1. Direct Addressing Mode:In direct addressing mode, address field in the instruction contains the effective address of the operand and no intermediate memory access is required. Now a days it is rarely used.
Example:Add the content of R1 and 1001 and store back to R1:
Add R1, (1001) 
Here 1001 is the address where operand is stored.
2. Indirect Addressing Mode:In Indirect addressing mode, address field in the instruction contains the memory location or register where effective address of operand is present. It requires two memory access. It is further classified into two categories: Register Indirect, and Memory Indirect.
Example:
LOAD R1, @500
Above instruction is used to load the content of memory location stored at memory location 500 to register R1. In other words we can say, effective address is stored at memory location 500.
Difference between Direct and Indirect Addressing Modes:
pp_pankaj
Computer Organization & Architecture
GATE CS
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Logical and Physical Address in Operating System
Computer Organization and Architecture | Pipelining | Set 1 (Execution, Stages and Throughput)
Memory Hierarchy Design and its Characteristics
Computer Organization | Von Neumann architecture
Computer Organization | RISC and CISC
Layers of OSI Model
ACID Properties in DBMS
TCP/IP Model
Page Replacement Algorithms in Operating Systems
Types of Operating Systems
pwdx - Unix, Linux Command

pwdx pids...
pwdx -V












Advertisements


    129 Lectures 
     23 hours 

 Eduonix Learning Solutions

    5 Lectures 
     4.5 hours 

 Frahaan Hussain

    35 Lectures 
     2 hours 

 Pradeep D

    41 Lectures 
     2.5 hours 

 Musab Zayadneh

    46 Lectures 
     4 hours 

 GUHARAJANM

    6 Lectures 
     4 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page