
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10402 Articles for Python

647 Views
Performing sort operations after every insertion on a long list may be expensive in terms of time consumed by processor. The bisect module ensures that the list remains automatically sorted after insertion. For this purpose, it uses bisection algorithm. The module has following functions:bisect_left()This method locates insertion point for a given element in the list to maintain sorted order. If it is already present in the list, the insertion point will be before (to the left of) any existing entries. The return value caan be used as the first parameter to list.insert()bisect_right()This method is similar to bisect_left(), but returns an ... Read More

284 Views
Array is a very popular data structure in C/C++, Java etc. In these languages array is defined as a collection of more than one elements of similar data type. Python doesn't have any built-in equivalent of array. It's List as well as Tuple is a collection of elements but they may of different types.Python's array module emulates C type array. The module defines 'array' class. Following constructor creates an array object:array(typecode, initializer)The typecode argument determines the type of array. Initializer should be a sequence with all elements of matching type.Following statement creates an integer array object:>>> import array >>> arr ... Read More

764 Views
Python developers can extend and modify the behavior of a callable functions, methods or classes without permanently modifying the callable itself by using decorators. In short we can say they are callable objects which are used to modify functions or classes.Function decorators are functions which accepts function references as arguments and adds a wrapper around them and returns the function with the wrapper as a new function.Let’s understand function decorator bye an example:Code1@decorator def func(arg): return "value"Above code is same as:Code2def func(arg): return "value" func = decorator(func)So from above, we can see a decorator is simply another function ... Read More

967 Views
Python provides two built-ins functions for “AND” and “OR” operations are All and Any functions.Python any() functionThe any() function returns True if any item in an iterable are true, otherwise it returns False. However, if the iterable object is empty, the any () function will return False.Syntaxany(iterable)The iterable object can be a list, tuple or dictionary.Example 1>>> mylst = [ False, True, False] >>> x = any(mylst) >>> x TrueOutputOutput is True because the second item is True.Example 2Tuple – check if any item is True>>> #Tuple - check if any item is True >>> mytuple = (0, 1, 0, ... Read More

307 Views
Though we all know python is not as fast or efficient as other complied languages. However, there are many big companies which shows us that python code can handle much bigger workload which shows it’s not that slow. In this section, we are going to see some of the tips that one should keep in mind so that a correct python program runs even faster and more efficient.Tip 1: Go for built-in functionsThough we can write efficient code in python, but it’s very hard to beat built-in functions(which are written in C). Below image shows the list of python built-in ... Read More

2K+ Views
In this we are going to see different ways of I/O methods for competitive programming in Python. In competitive programming it is important to read the input as fast as possible so as take advantage over others.Suppose you’re in a codeforces or similar online jude (like SPOJ) and you have to read numbers a, b, c, d and print their product. There are multiple ways to do, let’s explore them – one by oneOne way to doing it is either through list comprehension and map function.Method 1: Using a list comprehensiona, b, c, d = [int(x) for x in input().split()] ... Read More

394 Views
Python provides many ways to measure the time of execution for a piece of python code. One way is to use the python inbuilt time module and save the time before and after the execution of the program?Python timeitWhen some program is running, many processes also run in the background to make that code executable. The time module doesn’t count background processes execution time, however if you need precise time performance measurements timeit is the module to go for it.The timeit module runs the code approximately 1 million times (default value) and take into account the minimum amount of time ... Read More

6K+ Views
In Python, whenever we try to read or write files we don’t need to import any library as it’s handled natively. The open() function opens a file and returns a file object. The file objects contain methods and attributes which latter can be used to retrieve information or manipulate the file you opened. File Operations The file is a named location on the disk to store related information, as the file is having some name and location, it is stored in the hard disk. In Python, file operation is performed in the following order - ... Read More

2K+ Views
Python XML parser parser provides one of the easiest ways to read and extract useful information from the XML file. In this short tutorial we are going to see how we can parse XML file, modify and create XML documents using python ElementTree XML API.Python ElementTree API is one of the easiest way to extract, parse and transform XML data.So let’s get started using python XML parser using ElementTree:Example1Creating XML fileFirst we are going to create a new XML file with an element and a sub-element.#Import required library import xml.etree.ElementTree as xml def createXML(filename): # Start with the ... Read More

2K+ Views
For many people, image processing may seem like a scary and daunting task but it is not as hard as many people thought it is. In this tutorial we’ll be doing basic color detection in openCv with python.How does color work on a computer?We represent colors on a computers by color-space or color models which basically describes range of colors as tuples of numbers.Instead of going for each color, we’ll discuss most common color-space we use .i.e. RGB(Red, Green, Blue) and HSV (Hue, Saturation, Value).RGB basically describes color as a tuple of three components. Each component can take a value ... Read More