Set Clear in Python

Hafeezul Kareem
Updated on 11-Jul-2020 06:53:42

3K+ Views

In this tutorial, we are going to learn about the clear method of set data structure. Let's see details about the clear method.The method clear is used to clear all the data from the set data structure. All elements from set will clear. And we will leave with an empty set.Follow the below steps to see clear method in action.Initialize a set.User the clear method and clear the set.Print the set and you will see an empty one.Example Live Demo# initialzing a set number_set = {1, 2, 3, 4, 5} # clearing the set number_set.clear() # printing the set print(number_set)OutputIf you ... Read More

Set Add in Python

Hafeezul Kareem
Updated on 11-Jul-2020 06:51:05

268 Views

In this tutorial, we are going to learn about the add method of set data structure. Let's dive into the tutorial.Set data structure stores unique elements in it. The add method of set data structure takes an element and adds it to the set.Follow the below steps to add a new element to the set.Initialize a set.Add a new element to the set using the add method.Print the updated set.Example Live Demo# initialzing the set numbers_set = {1, 2, 3, 4, 4, 5} # adding an element to the set numbers_set.add(6) # printing the updated set print(numbers_set)OutputIf you run the above ... Read More

Send SMS Updates to Mobile Phone using Python

Hafeezul Kareem
Updated on 11-Jul-2020 06:49:54

2K+ Views

In this tutorial, we are going to learn how to send SMS in Python. We will be using Twilio for sending SMS.First of all, go the Twilio and create an account. You will get free trial account. And finish settings.We have to install a module called twilio to work with Twilio client. Install it with the following command.pip install twilioNow, go to the Twilio Documentation on how to send SMS using Twilio client. Or follow the steps to send the SMS.Import the twilio Client from twilio.rest.Get and store the account_sid and auth_token from the your Twilio account.Make instance of the ... Read More

Self in Python Class

Hafeezul Kareem
Updated on 11-Jul-2020 06:47:23

2K+ Views

In this tutorial, we are going to learn about the self in Python. You must be familiar with it if you are working with Python. We will see some interesting things about.Note − self is not a keyword in Python.Let's start with the most common usage of self in Python.We'll use self in classes to represent the instance of an object. We can create multiple of a class and each instance will have different values. And self helps us to get those property values within the class instance. Let's see ane example.Example# class class Laptop:    # init method   ... Read More

Implement Instance Method of an Arbitrary Object Using Method Reference in Java

raja
Updated on 11-Jul-2020 06:20:53

1K+ Views

A method reference is a new feature in Java 8, which is related to Lambda Expression. It can allow us to reference constructors or methods without executing them. The method references and lambda expressions are similar in that they both require a target type that consists of a compatible functional interface.SyntaxClass :: instanceMethodNameExampleimport java.util.*; import java.util.function.*; public class ArbitraryObjectMethodRefTest {    public static void main(String[] args) {       List persons = new ArrayList();       persons.add(new Person("Raja", 30));       persons.add(new Person("Jai", 25));       persons.add(new Person("Adithya", 20));       persons.add(new Person("Surya", 35));       persons.add(new ... Read More

Iterate Elements of List and Map Using Lambda Expression in Java

raja
Updated on 11-Jul-2020 06:15:14

11K+ Views

The lambda expressions are inline code that implements a functional interface without creating an anonymous class. In Java 8, forEach statement can be used along with lambda expression that reduces the looping through a Map to a single statement and also iterates over the elements of a list. The forEach() method defined in an Iterable interface and accepts lambda expression as a parameter.Example ( List using Lambda Expression)import java.util.*; public class ListIterateLambdaTest {    public static void main(String[] argv) {       List countryNames = new ArrayList();       countryNames.add("India");       countryNames.add("England");       countryNames.add("Australia");     ... Read More

Convert Object to Another Type Using Map Method with Lambda in Java

raja
Updated on 11-Jul-2020 06:13:04

9K+ Views

In Java 8, we have the ability to convert an object to another type using a map() method of Stream object with a lambda expression. The map() method is an intermediate operation in a stream object, so we need a terminal method to complete the stream.SyntaxStream map(Function

Type Inference in Lambda Expression in Java

raja
Updated on 11-Jul-2020 06:05:19

1K+ Views

Type Inference states that the data type of any expression. For instance, a method return type or argument type can be understood automatically by the compiler. Types in the argument list can be omitted since java already know the types of the expected parameters for the single abstract method of functional interface.Syntax(var1, var2 …) -> { method body }In the below example, we can sort a String[] array by its last character.Exampleimport java.util.Arrays; public class TypeInferencingLambdaTest {    public static void main(String[] args) {       String[] names = {"Raja", "Jai", "Adithya", "Surya", "Chaitanya", "Ravi", "Krishna"};       Arrays.sort(names, (s1, ... Read More

Maximum Sum Alternating Subsequence in C++

Ayush Gupta
Updated on 10-Jul-2020 14:20:34

175 Views

In this tutorial, we will be discussing a program to find maximum sum alternating subsequence.For this we will be provided with an array of integers. Our task is to find the maximum sum of an alternating subsequence i.e sequence which is first decreasing, then increasing, then decreasing and so on.Example Live Demo#include using namespace std; //returning maximum sum alternating series int maxAlternateSum(int arr[], int n) {    if (n == 1) return arr[0];    int dec[n];    memset(dec, 0, sizeof(dec));    int inc[n];    memset(inc, 0, sizeof(inc));    dec[0] = inc[0] = arr[0];    int flag = 0 ;    for (int i=1; i

Maximum Sub-Tree Sum in a Binary Tree that is also a BST in C++

Ayush Gupta
Updated on 10-Jul-2020 14:18:26

226 Views

In this tutorial, we will be discussing a program to find maximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST.For this we will be provided with a binary tree. Our task is to print the sum of a sub-tree which is also a binary search tree.Example Live Demo#include using namespace std; //creating binary tree node struct Node {    struct Node* left; struct Node* right; int data;    Node(int data) {       this->data = data;       this->left = NULL;       this->right = NULL;    } }; struct Info ... Read More

Advertisements