Deque Operator in C++ STL

Sunidhi Bansal
Updated on 05-Mar-2020 11:07:36

351 Views

In this article we will be discussing the working, syntax and examples of deque::operator= and deque::operator[] 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 allows users 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 Double ... Read More

Check Deque Size and Emptiness in C++ STL

Sunidhi Bansal
Updated on 05-Mar-2020 11:03:39

2K+ Views

In this article we will be discussing the working, syntax and examples of deque::empty() and deque::size() 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

Humanize Numbers with Python

Lakshmi Srinivas
Updated on 05-Mar-2020 10:59:25

350 Views

If you want something that converts integers to words like 99 to ninety-nine, you have to use an external package or build one yourself. The pynum2word module is pretty good at this task. You can install it using −$ pip install pynum2wordThen use it in the following way −>>> import num2word >>> num2word.to_card(16) 'sixteen' >>> num2word.to_card(23) 'twenty-three' >>> num2word.to_card(1223)'one thousand, two hundred and twenty-three'If you want to get results like 1.23 million for 1, 230, 000, you can use the humanize library to do so. You can install it using −$ pip install humanizeThen use it in the following way ... Read More

Importance of Collectors.flatMapping Method in Java 9

raja
Updated on 05-Mar-2020 10:58:50

547 Views

In Java 9, a new method added to the Collectors class: flatMapping(). It is similar to the Collectors.mapping() method in which the flatMapping() method allows us to handle nested collections. The Collectors.flatMapping() method takes a function to be applied to input elements and a collector to accumulate the elements passed through the function. Unlike the Collectors.mapping() method, the Collectors.flatMapping() method deals with a stream of elements that allows us to get rid of unnecessary intermediary collections.Syntaxpublic static Collector flatMapping(Function

Deque Begin and Deque End in C++ STL

Sunidhi Bansal
Updated on 05-Mar-2020 10:57:47

2K+ Views

In this article we will be discussing the working, syntax and examples of deque::begin() and deque::end() 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

Identify and Print Perfect Numbers in a Closed Interval Using Python

Chandu yadav
Updated on 05-Mar-2020 10:55:58

1K+ Views

A perfect number is a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is 6, which is the sum of 1, 2, and 3.You can find perfect numbers within a given range by testing each number for the given condition in the given range. exampledef print_perfect_nums(start, end):    for i in range(start, end + 1):    sum1 = 0    for x in range(1, i):       # Check if a divisor, if it is, add to sum       if(i % x == 0):          sum1 = sum1 + x          if (sum1 == i):             print(i) print_perfect_nums(1, 300)OutputThis will give the output6 28

Format Numbers to Strings in Python

V Jyothi
Updated on 05-Mar-2020 10:54:42

666 Views

You can format a floating number to a fixed width in Python using the format function on the string. examplenums = [0.555555555555, 1, 12.0542184, 5589.6654753] for x in nums:    print("{:10.4f}".format(x))OutputThis will give the output −0.5556 1.0000 12.0542 5589.6655ExampleUsing the same function, you can also format integers −nums = [5, 20, 500] for x in nums:    print("{:d}".format(x))OutputThis will give the output −5 20 500ExampleYou can use it to provide padding as well, by specifying the number before d:nums = [5, 20, 500] for x in nums:    print("{:4d}".format(x))OutputThis will give the output −5 20 500The https://pyformat.info/ website is a great ... Read More

Deque at and Deque Swap in C++ Programming STL

Sunidhi Bansal
Updated on 05-Mar-2020 10:53:35

230 Views

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

Compare Numbers in Python

Samual Sam
Updated on 05-Mar-2020 10:48:16

17K+ Views

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

Find Hash of File Using Python

Arjun Thakur
Updated on 05-Mar-2020 10:46:21

3K+ Views

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

Advertisements