copy and copy_if Function in C++

std::copy() and std::copy_if() function in C++ copies the elements in the range, to another range. However std::copy_if() function copies the element based on result of unary function passed to it. Syntax Syntax of copy() and copy_if() function is template <class InputIterator, class OutputIterator> OutputIterator copy (InputIterator first, InputIterator last, OutputIterator [...]

By |2020-09-23T16:51:45+05:30September 23rd, 2020|Categories: Programming|Tags: |

Numeric Operator Overload in Python

Plus (+) operator is used for adding numbers and at the same time to concatenate strings. It is possible because + operator is overloaded by both int class and str class. Operators are methods, defined in respective classes. Defining methods for operators is known as Operator Overloading. To use + [...]

By |2020-09-21T18:37:13+05:30September 21st, 2020|Categories: Programming|Tags: |

Comparing Object Instances in Python

Rich comparison methods are used for comparing object instances. It assigns special methods to each operator as given in below table. OperatorMethod==__eq__(self, other)!=__ne__(self, other)<__lt__(self, other)<=__le__(self, other)>__gt__(self, other)>=__ge__(self, other) The correspondence between operator symbols and method names is as follows: x < y calls x.__lt__(y), x>=y calls x.__ge__(y), and so on. [...]

By |2020-09-21T17:02:59+05:30September 21st, 2020|Categories: Programming|Tags: |

String Representation of Class Object in Python

Python module __str__() and __repr__() functions are used to convert class object into string. These functions can be are very helpful in debugging by logging useful information of the object. _str_ Function It is called by str() and the built-in functions format() and print() to compute printable string representation of [...]

By |2020-09-21T15:26:13+05:30September 21st, 2020|Categories: Programming|Tags: |

Enumerations in Python

Enumerations are a set of symbolic names bound to unique, constant values. Within an enumeration in Python, the members can be compared, and the enumeration itself can be iterated over. Because Enums are used to represent constants, it is recommended to use UPPER_CASE names for enum members. Enum Types enum [...]

By |2020-09-21T13:16:23+05:30September 21st, 2020|Categories: Programming|Tags: |

Counter in Python

Counter is used to keeps track of how many times equivalent values are added. It is a collection where elements are stored as dictionary keys and their counts are stored as dictionary values. Syntax To create a counter, use below syntax collections.Counter([iterable-or-mapping]) It returns counter object. A Counter is a [...]

By |2020-09-17T11:15:13+05:30September 16th, 2020|Categories: Programming|Tags: |

Deque in Python

A deque is a double-ended queue in which elements can be both inserted and deleted from either the left or the right end of the queue. deque class in Python supports deque. It is a generalization of stacks and queues. It support thread-safe, memory efficient appends and pops from either [...]

By |2020-09-16T17:52:57+05:30September 16th, 2020|Categories: Programming|Tags: |

DefaultDict in Python

defaultdict is a subclass of the built-in dict class. Its functionality is the same as that of dict class, expect it allows new key to be given a default value based on the type of dictionary being created. Syntax To create defaultdict, use below syntax collections.defaultdict([default_factory[, …]]) It returns a [...]

By |2020-09-16T15:39:16+05:30September 16th, 2020|Categories: Programming|Tags: |

OrderedDict in Python

Ordered dictionaries are just like regular dictionaries but have some extra capabilities relating to ordering operations. Both ordered dictionary and the built-in dict can remember insertion order. Some differences from dict are: Regular dict is efficient at mapping operations, but tracking insertion order is secondary. OrderedDict in Python is efficient [...]

By |2020-09-16T13:54:06+05:30September 16th, 2020|Categories: Programming|Tags: |

Namedtuple in Python

Standard tuple uses numerical indexes to access its members. Remembering index for each value can lead to errors, especially if the tuple has a lot of fields. A namedtuple in Python assigns names, as well as the numerical index, to each member. It allow for more readable, self-documenting code. They [...]

By |2020-09-16T12:57:14+05:30September 16th, 2020|Categories: Programming|Tags: |
Go to Top