Server Side Programming Articles - Page 1885 of 2650

How to create an unordered_map of pairs in C++?

Ayush Gupta
Updated on 25-Feb-2020 07:31:23

946 Views

In this tutorial, we will be discussing a program to understand how to create an unordered map of pairs in C++.Unordered maps are the ones that don't contain hash function for the pairs by default. If we want a hash value for a particular pair, it needs to be passed on explicitly.Example Live Demo#include using namespace std; //to hash any given pair struct hash_pair {    template    size_t operator()(const pair& p) const{       auto hash1 = hash{}(p.first);       auto hash2 = hash{}(p.second);       return hash1 ^ hash2;    } }; int main(){ ... Read More

How to create a List with Constructor in C++ STL

Ayush Gupta
Updated on 25-Feb-2020 07:28:17

259 Views

In this tutorial, we will be discussing a program to understand how to create a List with constructor in C++ STL.List are data structures to store elements in memory in a non-contiguous fashion. They are insertion and deletion quick as compared to vectors.Example Live Demo#include #include using namespace std; //printing the list void print_list(list mylist){    list::iterator it;    //printing all the elements    for (it = mylist.begin(); it != mylist.end(); ++it)       cout

How to add “graphics.h” C/C++ library to gcc compiler in Linux

Ayush Gupta
Updated on 25-Feb-2020 07:25:35

2K+ Views

In this tutorial, we will be discussing a program to understand how to add “graphics.h” C/C++ library to gcc compiler in Linux.To do this we are required to compile and install the libgraph package.This includes install build-essential and some external packages>>sudo apt-get install build-essential >>sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-2.0 guile-2.0-dev libsdl1.2debian libart-2.0-dev libaudiofile-dev libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev libxext-dev x11proto-xext-dev libfreetype6 libaa1 libaa1-dev libslang2-dev libasound2 libasound2-devThen setting the path in the extracted files>>sudo make install >>sudo cp /usr/local/lib/libgraph.* /usr/libExample#include #include #include int main(){    int gd = DETECT, gm;    initgraph(&gd, &gm, NULL);    circle(40, 40, 30);    delay(40000); ... Read More

How does a vector work in C/C++

Ayush Gupta
Updated on 25-Feb-2020 07:20:01

3K+ Views

In this tutorial, we will be discussing a program to understand how vectors work in C/C++.A vector data structure is an enhancement over the standard arrays. Unlike arrays, which have their size fixed when they are defined; vectors can be resized easily according to the requirement of the user.This provides flexibility and reduces the time requirement with arrays to copy the previous elements to the newly created array.Example Live Demo#include #include using namespace std; int main(){    vector myvector{ 1, 2, 3, 5 };    myvector.push_back(8);    //not vector becomes 1, 2, 3, 5, 8    for (auto x : myvector)    cout

Python - Get items in sorted order from given dictionary

Pradeep Elance
Updated on 18-Feb-2020 12:09:13

203 Views

The Python dictionary has key and value pairs. In some situation we will need the items of the dictionary to be sorted according to the keys. In this article we'll see the different ways to get a sorted output from the items in the dictionary.Using Operator ModuleThe Operator module has itemgetter function which can take 0 as the index of input parameter for the keys of the dictionary. We apply the sorted function on top of itemgetter and get the sorted output.Example Live Demodict = {12 : 'Mon', 21 : 'Tue', 17: 'Wed'} import operator print("Given dictionary", str(dict)) print ("sorted order ... Read More

Collapsible Pane in Tkinter Python

Pradeep Elance
Updated on 18-Feb-2020 12:03:15

1K+ Views

Tkinter is the GUI building library of python. In this article we will see how we can create a collapsible pane. They are usefult when we have some large amount of data to be displayed over a GUI canvas but we do not want to be displayed always. It is made collapsible so that it can be displayed as and when needed.The below program creates the collapsible pane where we see the result both after expanding and contracting the arrow. The code comments indicate the approach we take at each step.Examplefrom tkinter import * import tkinter as tk from tkinter ... Read More

Binning method for data smoothing in Python

Pradeep Elance
Updated on 18-Feb-2020 11:57:55

1K+ Views

Many times we use a method called data smoothing to make the data proper and qualitative for statistical analysis. During the smoking process we define a range also called bin and any data value within the range is made to fit into the bin. This is called the binning method. Below is an example of binning. Then we will see how we can achieve the binning method using a Python program.Binning ExampleLet’s take a series of numbers. Find the maximum and minimum values. Decide on the number of bins we need depending on how many data points the analysis needs. ... Read More

ASCII art using Python pyfiglet module

Pradeep Elance
Updated on 18-Feb-2020 11:51:29

2K+ Views

The ASCII text can be used to display many stylish texts by using the module pyfiglet. After installing this module we can use it to control the font that can be used to display the result. In the below program we see various results by choosing various font types.Example# import pyfiglet module import pyfiglet #Text in default font out = pyfiglet.figlet_format("Point") print(out)OutputRunning the above code gives us the following result −Example# import pyfiglet module import pyfiglet #Text in slant font out = pyfiglet.figlet_format("Point", font="slant") print(out)OutputRunning the above code gives us the following result −Example# import pyfiglet module import pyfiglet #Text ... Read More

Adding K to each element in a Python list of integers

Disha Verma
Updated on 18-Feb-2020 11:31:07

1K+ Views

In this article, we will learn how to add a constant K value to each element in a Python list of integers. A list is a data type in Python that stores a sequence of items separated by commas, like this − List = [item1, item2, item3…] Suppose we have a list of integers called "a" and a constant value "k." We need to add this "k" to each item in the "a" list. For example − Input: a = [5, 10, 15, 20] k = 5 Output: #On adding 5 to each element of the ... Read More

Add one Python string to another

Pradeep Elance
Updated on 18-Feb-2020 11:28:35

403 Views

By adding strings in python we just concatenate them to get a new string. This is useful in many scenarios like text analytics etc. Below are the two approaches we consider for this task.Using += OperatorThe + operator can be used for strings in a similar was as it is for numbers. The only difference being, in case of strings the concatenation happens and not a numeric addition.Example Live Demos1 = "What a beautiful " s2 = "flower " print("Given string s1 : " + str(s1)) print("Given string s2 : " + str(s2)) #Using += operator res1 = s1+s2 print("result ... Read More

Advertisements