In this article we will be discussing the working, syntax and examples of deque::at() and deque::swap() functions in C++ STL.What is Deque?Deque is the Double Ended Queues that are the sequence containers which provides the functionality of expansion and contraction on both the ends. A queue data structure allow user to insert data only at the END and delete data from the FRONT. Let’s take the analogy of queues at bus stops where the person can be inserted to a queue from the END only and the person standing in the FRONT is the first to be removed whereas in ... Read More
You can use relational operators in python to compare numbers(both float and int) in python. These operators compare the values on either side of them and decide the relation among them. Assume variable a holds 10 and variable b holds 20, thenOperatorExample==(a == b) is not true.!=(a != b) is true.>(a > b) is not true.=(a >= b) is not true.= b) print(a
You can find the hash of a file using the hashlib library. Note that file sizes can be pretty big. Its best to use a buffer to load chunks and process them to calculate the hash of the file. You can take a buffer of any size.Exampleimport sys import hashlib BUF_SIZE = 32768 # Read file in 32kb chunks md5 = hashlib.md5() sha1 = hashlib.sha1() with open('program.cpp', 'rb') as f: while True: data = f.read(BUF_SIZE) if not data: break md5.update(data) sha1.update(data) print("MD5: {0}".format(md5.hexdigest())) print("SHA1: {0}".format(sha1.hexdigest()))OutputThis will give the outputMD5: 7481a578b20afc6979148a6a5f5b408d SHA1: ... Read More
In this article we will be discussing the working, syntax and examples of list::emplace_front() and list::emplace_back() function in C++ STL.What is a List in STL?List 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 performs 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 ... Read More
The ord function in python gives the ordinal value of a character(ASCII). You can use this function to find the ascii codes as followsExamples = "Hello" for c in s: print(ord(c))OutputThis will give the output72 101 108 108 111
In this article we are going to discuss the set::value_comp() in C++ STL, their syntax, working and their return values.What is Set in C++ STL?Sets in C++ STL are the containers which must have unique elements in a general order. Sets must have unique elements because the value of the element identifies the element. Once added a value in set container later can’t be modified, although we can still remove or add the values to the set. Sets are used as binary search trees.What is set::value_comp()?value_comp() is an inbuilt function in C++ STL which is declared in header file. ... Read More
Python provides straightforward functions to convert Decimal to Binary, Octal, and Hexadecimal. These functions are −Binary: bin() Octal: oct() Hexadecimal: hex()ExampleYou can use these functions as follows to get the corresponding representation −decimal = 27 print(bin(decimal),"in binary.") print(oct(decimal),"in octal.") print(hex(decimal),"in hexadecimal.")OutputThis will give the output −0b11011 in binary. 0o33 in octal. 0x1b in hexadecimal.
In this article we are going to discuss the set::upper_bound() in C++ STL, their syntax, working and their return values.What is Set in C++ STL?Sets in C++ STL are the containers which must have unique elements in a general order. Sets must have unique elements because the value of the element identifies the element. Once added a value in set container later can’t be modified, although we can still remove or add the values to the set. Sets are used as binary search trees.What is set::upper_bound()?upper_bound() is an inbuilt function in C++ STL which is declared in header file. ... Read More
You can create the multiplication table for any number using a simple loop. exampledef print_mul_table(num): for i in range(1, 11): print("{:d} X {:d} = {:d}".format(num, i, num * i)) print_mul_table(5)OutputThis will give the output5 X 1 = 5 5 X 2 = 10 5 X 3 = 15 5 X 4 = 20 5 X 5 = 25 5 X 6 = 30 5 X 7 = 35 5 X 8 = 40 5 X 9 = 45 5 X 10 = 50
You can create a list of the three numbers and call the max method to find the largest among them. examplemy_list = [10, 12, 3] print(max(my_list))OutputThis will give the output −12ExampleIf you want to calculate it yourself, you can create a simple function likedef max_of_three(a, b, c): if a > b and a > c: return a elif b > c: return b else: return c print(max_of_three(10, 12, 3))OutputThis will give the output −12