Programming Articles - Page 2087 of 3366

Bigram formation from given a Python list

Pradeep Elance
Updated on 26-Feb-2020 07:42:18

833 Views

A bigram is formed by creating a pair of words from every two consecutive words from a given sentence. In python, this technique is heavily used in text analytics. Below we see two approaches on how to achieve this.Using enumerate and splitUsing these two methods we first split the sentence into multiple words and then use the enumerate function to create a pair of words from consecutive words.Example Live Demolist = ['Stop. look left right. go'] print ("The given list is : " + str(list)) # Using enumerate() and split() for Bigram formation output = [(k, m.split()[n + 1]) for m ... Read More

Avoiding quotes while printing strings in Python

Pradeep Elance
Updated on 26-Feb-2020 07:39:41

202 Views

If we print a given list of strings as it is, we have to use quotes and fill in a pair of matching quotes appropriately. We can avoid using quotes in the print statements by following two approaches.Using join()The join method helps us in printing the output of list elements by using any separator we choose. In the below example we choose ** as separator.Example Live Demolist = ['Mon', 'Tue', 'Wed'] # The given list print("The given list is : " + str(list)) print("The formatted output is : ") print(' ** '.join(list))OutputRunning the above code gives us the following result −The ... Read More

askopenfile() function in Python Tkinter

Pradeep Elance
Updated on 26-Feb-2020 07:36:06

2K+ Views

Instead of hard coding the path to a file to be used by a python program, we can allow the user to browse the os folder structure using a GUI and let the user select the file. This is achieved using the tkinter module in which we define a canvas and put a button on it to browse the files.In the below program, we define a file opener function. We only use this function to open a text file as python can read the content of a text file and print it out in a much readable manner. We can ... Read More

What are the characteristics of a module in Java 9?

raja
Updated on 26-Feb-2020 05:01:28

352 Views

The module is a collection of code, data, and resources. It is a set of related packages and types like classes, abstract classes, and interfaces with code, data files, and some static resources.Below are some of the characteristics of a module.Characteristics of a module:A module must define an interface for communication with other modules.A module defines the separation between a module interface and module implementation.A module presents a set of properties that contains information.Two or more modules have nested together.A module has a clear, defined responsibility. Each function implemented by only one module.A module must able to tested independently from other modules.An error in a module can't propagate to other ... Read More

Differences between Optional.ifPresentOrElse() and Optional.or() methods in Java 9?

Alshifa Hasnain
Updated on 11-Jun-2025 13:44:57

4K+ Views

In this article, we will learn about the differences between Optional.ifPresentOrElse() and Optional.or() methods in Java 9. Both Optional.ifPresentOrElse() and Optional.or() methods were introduced in Java 9 to improve its functionality. Optional Class Optional Class is a part of java.util package, and it was introduced in Java 8. It is a container object that may or may not contain a non-null value. It helps in writing code without using too many null checks. The following are some of the common methods of the Optional Class: empty(): This method returns an empty Optional instance. ... Read More

How to handle an exception in JShell in Java 9?

Alshifa Hasnain
Updated on 11-Jun-2025 13:43:05

452 Views

In this article, we will learn to handle an exception in JShell in Java 9. We will learn about the JShell, exceptions in Java, JShell exceptions, their handling, and Types of exceptions in JShell with examples. What is JShell? JShell is a new command-line interactive REPL (Read-Evaluate-Print-Loop) tool introduced in Java 9 to evaluate declarations, statements, and expressions written in Java. This tool also allows us to execute Java code snippets and get immediate results. C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> JShell provides a fast and friendly environment that ... Read More

How to convert a class to another class type in C++?

Ayush Gupta
Updated on 25-Feb-2020 09:15:13

5K+ Views

In this tutorial, we will be discussing a program to understand how to convert a class to another class type in C/C++.Class conversion can be done with the help of operator overloading. This allows data of one class type to be assigned to the object of another class type.Example Live Demo#include using namespace std; //type to which it will be converted class Class_type_one {    string a = "TutorialsPoint";    public:       string get_string(){          return (a);    }    void display(){       cout

How to find the sum of elements of a Vector using STL in C++?

Ayush Gupta
Updated on 25-Feb-2020 09:12:10

840 Views

In this tutorial, we will be discussing a program to understand how to find the sum of elements of a vector using STL in C++.To find the sum of elements of a given vector, we would be using the accumulate() method from the STL library.Example Live Demo#include using namespace std; int main(){    //defining the vector    vector a = { 1, 45, 54, 71, 76, 12 };    cout

How to find the maximum element of a Vector using STL in C++?

Nishu Kumari
Updated on 19-Aug-2025 17:15:15

7K+ Views

A vector in C++ is a dynamic array that stores elements of the same data type and can change its size when needed. In this article, we are given a vector and our goal is to find the maximum (largest) element using different STL methods in C++. Let's understand this with an example: // Example 1 std::vector vec1 = {11, 13, 21, 45, 8}; The largest element is 45. // Example 2 std::vector vec2 = {1, 9, 2, 5, 7}; The largest element is 9. Finding Maximum Element of a Vector Using STL in ... Read More

How to create an unordered_set of user defined class or struct in C++?

Ayush Gupta
Updated on 25-Feb-2020 07:49:36

797 Views

In this tutorial, we will be discussing a program to understand how to create an unordered set of user defined class or struct in C++.For this we will create a structure type and then compare two structure types with the function defined by the user to store the hash function.Example#include using namespace std; //defined structure struct Test {    int id;    bool operator==(const Test& t) const{       return (this->id == t.id);    } }; //defined class for hash function class MyHashFunction {    public:       size_t operator()(const Test& t) const{         ... Read More

Advertisements