Partial Functions in Python

George John
Updated on 30-Jul-2019 22:30:26

1K+ Views

Everybody loves to write reusable code, right? Then partial function is a cool thing to learn. Partial functions allows us to derive a function with x parameters to a function with fewer parameters and constant values set for the more limited function.We can write partial functional application in python through functools library. Below is a simple example of partial function from the functools library with the add function from the operator library.>>> from functools import * >>> from operator import * >>> add(1, 2) 3 >>> add1 = partial(add, 4) >>> add1(6) 10 >>> add1(10) 14Partial is a higher order ... Read More

Incompatibilities Between C and C++

Smita Kapse
Updated on 30-Jul-2019 22:30:26

165 Views

Here we will see some incompatibilities between C and C++. Some C codes that can be compiled using C compiler, but does not compile in C++ compiler. And also returns error.We can define function using a syntax, that optionally specify the argument types after the argument list.Example#include void my_function(x, y)int x;int y; { // Not valid in C++    printf("x = %d, y = %d", x, y); } int main() {    my_function(10, 20); }Outputx = 10, y = 20OutputError in C++ :- x and y was not declared in this scopeIn C, or some older version of C++, the ... Read More

Move ResultSet Cursor to Next Row in JDBC

Vikyath Ram
Updated on 30-Jul-2019 22:30:26

1K+ Views

Whenever we execute SQL statements using the executeQuery() method, it returns a ResultSet object which holds the tabular data returned by the SELECT queries(in general).The ResultSet object contains a cursor/pointer which points to the current row. Initially this cursor is positioned before first row (default position).You can move the cursor of the ResultSet object to the next row from the current position, using the next() method of the ResultSet interface.rs.next()This method returns a boolean value specifying whether the ResultSet object contains more rows.If there are no rows next to its current position this method returns false, else it returns true.Let us create ... Read More

Count Size of an Array Distinctly in MongoDB

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

267 Views

Use DISTINCT for distinct elements and then length to get the size of array −db.yourCollectionName.distinct('yourFieldName').length;Let us first create a collection with documents −> db.countOrSizeDemo.insertOne({"StudentFirstName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd304f5b64f4b851c3a13dc") } > db.countOrSizeDemo.insertOne({"StudentFirstName":"David"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd304fab64f4b851c3a13dd") } > db.countOrSizeDemo.insertOne({"StudentFirstName":"David"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd304fcb64f4b851c3a13de") } > db.countOrSizeDemo.insertOne({"StudentFirstName":"Carol"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd30500b64f4b851c3a13df") } > db.countOrSizeDemo.insertOne({"StudentFirstName":"Sam"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd30505b64f4b851c3a13e0") } > db.countOrSizeDemo.insertOne({"StudentFirstName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd3050ab64f4b851c3a13e1") }Following is the query to display all ... Read More

Implement MongoDB toLowerCase in a foreach Loop to Update Student Names

Anvi Jain
Updated on 30-Jul-2019 22:30:26

176 Views

Let us first create a collection with documents wherein one of the fields is StudentName −> db.lowerCaseDemo.insertOne({"StudentName":"JOHN SMith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd9a86fb50a6c6dd317ad9f") } > db.lowerCaseDemo.insertOne({"StudentName":"CAROL TAYLor"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd9a88fb50a6c6dd317ada0") } > db.lowerCaseDemo.insertOne({"StudentName":"DAVID Miller"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd9a89fb50a6c6dd317ada1") }Following is the query to display all documents from a collection with the help of find() method −> db.lowerCaseDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd9a86fb50a6c6dd317ad9f"),    "StudentName" : "JOHN SMith" } {    "_id" : ObjectId("5cd9a88fb50a6c6dd317ada0"),    "StudentName" : "CAROL TAYLor" } { ... Read More

HTML DOM Anchor href Property

Chandu yadav
Updated on 30-Jul-2019 22:30:26

185 Views

The HTML DOM Anchor href property is used to set or return the href attribute. It returns the url of the link.Following is the syntax to set the anchor href property−anchorObj.href = URLAbove, URL is the url of the link. It can be an absolute, relative or anchor link with a hash.Following is the syntax to return the anchor href property−anchorObj.hrefLet us now see an example to implement the DOM Anchor href property−Example Live Demo Company Our Team Display href Part Display Host Part Display Hostname function display() { var a = document.getElementById("mylink").href; ... Read More

Find the Perimeter of a Rhombus Using Diagonals

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

279 Views

Rhombus is a simple quadrilateral whose four sides all have the same length. And perimeter of rhombus can be found by two methods.Adding all side.Using the diagonalsA quadrilateral has two diagonal and based on the length of diagonals the area and perimeter of the quadrilateral can be found.To find the perimeter of a rhombus using its diagonals is 2{√(d1)2 + (d2)2 }LOGIC − To find the perimeter of a rhombus using its diagonals. You need the formula 2{√(d1)2 + (d2)2 } for this in your code you need to use the math class that supports the use of squareRoot and ... Read More

HTML DOM Input Date Disabled Property

Rama Giri
Updated on 30-Jul-2019 22:30:26

139 Views

The HTML DOM Input Date disabled property sets/returns whether Input Date is enabled or disabled.SyntaxFollowing is the syntax −Returning boolean value - true/falseinputDateObject.disabledSetting disabled to booleanValueinputDateObject.disabled = booleanValueBoolean ValueHere, “booleanValue” can be the following −booleanValueDetailstrueIt defines that the input date is disabled.falseIt defines that the input date is not disabled and it is also the default value.ExampleLet us see an example of Input Date disabled property − Live Demo Input Date Disabled Date Select: Enable Date Input    var divDisplay = document.getElementById("divDisplay");    var inputDate = document.getElementById("dateSelect");    divDisplay.textContent = 'Date Input disabled: ... Read More

HTML DOM Input Time Required Property

AmitDiwan
Updated on 30-Jul-2019 22:30:26

148 Views

The HTML DOM Input Time required property determines whether Input Time is compulsory to set or not.SyntaxFollowing is the syntax −Returning boolean value - true/falseinputTimeObject.requiredSetting required to booleanValueinputTimeObject.required = booleanValueBoolean ValuesHere, “booleanValue” can be the following −booleanValueDetailstrueIt is compulsory to set the time field to submit form.falseIt is the default value and to set time field is not compulsory.ExampleLet us see an example of Input Time required property − Live Demo Input Time required    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {     ... Read More

Hygienic Macros in C

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

574 Views

Here we will see the Hygienic Macros in C. We know the usage of macros in C. But sometimes, it does not return the desired results because of accidental capture of identifiers.If we see the following code, we can see that it is not working properly.Example#include #define INCREMENT(i) do { int a = 0; ++i; } while(0) main(void) {    int a = 10, b = 20;    //Call the macros two times for a and b    INCREMENT(a);    INCREMENT(b);    printf("a = %d, b = %d", a, b); }After preprocessing the code will be like this −Example#include #define ... Read More

Advertisements