Found 26504 Articles for Server Side Programming

list unique( ) in C++ STL

Sunidhi Bansal
Updated on 26-Feb-2020 10:55:05

384 Views

Given is the task to show the functionality list unique( ) function in C++ in STL.What is List in STLList are containers that allow constant time insertion and deletion anywhere in sequence. List are implemented as doubly linked lists. List allow non-contiguous memory allocation. List perform better insertion extraction and moving of element in any position in container than array, vector and deque. In List the direct access to the element is slow and list is similar to forward_list, but forward list objects are single linked lists and they can only be iterated forwards.What is unique( )The list unique( ) ... Read More

list begin( ) and list end( ) in C++ STL

Sunidhi Bansal
Updated on 26-Feb-2020 10:47:14

590 Views

Given is the task to show the functionality list begin( ) and list end( ) function in C++ in STL.What is List in STLList is a data structure that allows constant time insertion and deletion anywhere in sequence. Lists are implemented as doubly linked lists. Lists allow non-contiguous memory allocation. List perform better insertion extraction and moving of element in any position in container than array, vector and deque. In List the direct access to the element is slow and list is similar to forward_list, but forward list objects are single linked lists and they can only be iterated forwards.What ... Read More

Python - Convert column to separate elements in list of lists

Pradeep Elance
Updated on 26-Feb-2020 08:11:19

308 Views

In analyzing data or processing data using python, we come across situations where the given list has to be remodeled or reshaped to get lists with different columns. We can achieve that with multiple approaches as discussed below.Using SlicingWe can slice the list at certain elements to create the columnar structure. Here we convert the given list into a new list where the elements are split form the middle. We sue two for loops. The outer one splits the elements from the zeroth element to the second element and the inner one from the second element to the last.Example Live Demox ... Read More

Python - Convert a set into dictionary

Pradeep Elance
Updated on 26-Feb-2020 08:06:33

3K+ Views

Python provides lot of flexibility to handle different types of data structures. There may be a need when you have to convert one Data Structure to another for a better use or better analysis of the data. In this article we will see how to convert a Python set to a Python dictionary.Using zip and dictThe dict() can be used to take input parameters and convert them to a dictionary. We also use the zip function to group the keys and values together which finally become the key value pair in the dictionary.Example Live Demolist_keys = {1, 2, 3, 4} list_values ... Read More

How to print double quotes with the string variable in Python?

Pradeep Elance
Updated on 26-Feb-2020 07:54:40

14K+ Views

Printing double quotes is tricky, as it itself is required as part of syntax to print the strings by surrounding them. In this article we will see how these double quotes can be printed using print statement.The below scenarios will not print the double quote. The first two lines of code will give no output while the last one will through error.Example Live Demoprint(" ") print(" " " ") print(""aString"")OutputRunning the above code gives us the following result −;print(""aString"") ^ SyntaxError: invalid syntaxBut if we surround the strings with proper quotes as shown below, then the quotes can themselves get printed. ... Read More

Bigram formation from given a Python list

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

822 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

186 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

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

821 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

Advertisements