Pradeep Elance has Published 445 Articles

Extending a list in Python (5 different ways)

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:38:07

2K+ Views

Lists are the most frequently used data structures of python. When we want to add more elements to a list, the extension of list happens. This can be done in following 5 different ways.Using the Plus operatorHere we simply add the elements of a new list using the + operator. ... Read More

divmod() in Python and its application

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:32:04

1K+ Views

The divmod() is part of python’s standard library which takes two numbers as parameters and gives the quotient and remainder of their division as a tuple. It is useful in many mathematical applications like checking for divisibility of numbers and establishing if a number is prime or not.SyntaxSyntax: divmod(a, b) ... Read More

Different ways to clear a list in Python

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:27:03

5K+ Views

Clearing up all the elements in a python list can be done in many ways. Below are the some of the methods which are implemented to achieve this.using clear()This function is a part of standard library and empties the python list completely.Syntax: list_name.clear() list_name is the name of the list ... Read More

delattr() and del() in Python

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:22:01

367 Views

These two functions are used to remove attributes from classes. The delattr() allows dynamoc deletion of attribute while the del() is more efficient explicit in deleting the attribute.Using delattr()Syntax: delattr(object_name, attribute_name) Where object name is the name of the object, instantiated form the class. Attribute_name is the name of the ... Read More

Count frequencies of all elements in array in Python using collections module

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:18:37

245 Views

As python allows duplicate elements in a list we can have one element present multiple Times. The frequency of elements in a list indicates how many times an element occurs in a list. In this article we use the Counter function of the collections module to find out the frequency ... Read More

Count distinct elements in an array in Python

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:15:52

481 Views

In a list in Python we may have duplicate elements. When we count the length of the list we get the total length including the duplicate elements. But in this article we will see how to get the total count of the distinct elements or unique elements in a list.ExampleIn ... Read More

casefold() string in Python

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:10:47

105 Views

This function is helpful in converting the letters of a word into lowercase. When applied to two strings it can match their values irrespective of the type up of the case of the letters.Applying casefold()The below example we apply the casefold() function to a string and the result comes out ... Read More

Capitalize first letter of a column in Pandas dataframe

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:09:11

974 Views

A pandas dataframe is similar to a table with rows and columns. Sometimes we may have a need of capitalizing the first letters of one column in the dataframe which can be achieved by the following methods.Creating a DataframeIn the below example we first create a dataframe with column names ... Read More

callable() in Python

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 08:05:13

247 Views

The callable() function in python is part of its standard library which returns true if the object is callable and returns false if it is not.The object itself should have a call method to be callable. For example if we just declare a variable with value, it is not callable, ... Read More

bin() in Python

Pradeep Elance

Pradeep Elance

Updated on 07-Aug-2019 07:57:15

777 Views

The bin() function converts a decimal to binary. You can use a positive or negative integer as the parameter to be converted.SyntaxBelow is the syntax of the function.bin(n) Parameters : an integer to convert Return Value : A binary string of an integer or int object. Exceptions : Raises TypeError ... Read More

Advertisements