Pradeep Elance has Published 446 Articles

Comprehensions in Python

Pradeep Elance

Pradeep Elance

Updated on 17-Oct-2019 12:10:37

3K+ Views

We can create new sequences using a given python sequence. This is called comprehension. It basically a way of writing a concise code block to generate a sequence which can be a list, dictionary, set or a generator by using another sequence. It may involve multiple steps of conversion between ... Read More

colorsys module in Python

Pradeep Elance

Pradeep Elance

Updated on 17-Oct-2019 12:07:25

847 Views

This module allows bidirectional conversions of color values between colors expressed in the RGB (Red Green Blue) and other color spaces. The three other color spaces it uses are YIQ (Luminance (Y) In-phase Quadrature), HLS (Hue Lightness Saturation) and HSV (Hue Saturation Value). All the coordinates can be between 0 ... Read More

classmethod() in Python

Pradeep Elance

Pradeep Elance

Updated on 17-Oct-2019 12:03:20

356 Views

A class method receives the class itself as its first argument. This way we are able to call the method inside a class without first creating an instance from the class. We just use the decorator @classmethod before the declaration of the method contained in the class and then we ... Read More

Check if both halves of the string have same set of characters in Python

Pradeep Elance

Pradeep Elance

Updated on 17-Oct-2019 11:56:42

204 Views

We can split a long string from the middle and check if the two halves are equal or not. The input string may have an odd or even number of characters. If it has an even number of characters, we divide the two halves by taking half of the length. ... Read More

Check for balanced parentheses in Python

Pradeep Elance

Pradeep Elance

Updated on 17-Oct-2019 11:53:22

747 Views

Many times we are required to find if an expression is balanced with respect to the brackets present in it. By balanced we mean for each left bracket there is a corresponding right bracket and the sequence of brackets is properly ordered. This has importance in writing a program or ... Read More

Python eval()

Pradeep Elance

Pradeep Elance

Updated on 23-Aug-2019 12:43:20

472 Views

The eval() method parses the expression passed on to this method and runs the expression within the program. In other words, it interprets a string as code inside a python program.SyntaxThe Syntax for eval is as below −eval(expression, globals=None, locals=None)WhereExpression − It is the python expression passed onto the method.globals ... Read More

How to split a string in Python

Pradeep Elance

Pradeep Elance

Updated on 23-Aug-2019 12:38:50

318 Views

Manytimes we need to split a given string into multiple parts based on some delimiter. Python provides a function named split() which can be used to achieve this. It also provides a way to control the delimiter and number of characters to be considered as delimiter.ExampleIn the below example we ... Read More

Help function in Python

Pradeep Elance

Pradeep Elance

Updated on 23-Aug-2019 12:31:41

150 Views

Many times we need to look into the python documentation for some help on functions, modules etc. Python provides a help function that gives us this needed results.SyntaxHelp(‘term’) Where term is the word on which we want the help.ExampleIn the below example we seek to find help on the word ... Read More

Filter in Python

Pradeep Elance

Pradeep Elance

Updated on 23-Aug-2019 12:29:22

300 Views

We sometimes arrive at a situation where we have two lists and we want to check whether each item from the smaller list is present in the bigger list or not. In such case we use the filter() function as discussed below.SyntaxFilter(function_name, sequence name)Here Function_name is the name of the ... Read More

factorial() in Python

Pradeep Elance

Pradeep Elance

Updated on 23-Aug-2019 12:26:17

6K+ Views

Finding the factorial of a number is a frequent requirement in data analysis and other mathematical analysis involving python. The factorial is always found for a positive integer by multiplying all the integers starting from 1 till the given number. There can be three approaches to find this as shown ... Read More

Advertisements