Found 10476 Articles for Python

Python Input Methods for Competitive Programming?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

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

Timeit in Python with Examples?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

419 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

File Objects in Python?

SaiKrishna Tavva
Updated on 09-Oct-2024 14:26:27

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

XML parsing in Python?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

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

Detection of a specific color(blue here) using OpenCV with Python?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

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

How to use contains() in android LinkedBlockingDeque?

Samual Sam
Updated on 30-Jun-2020 14:13:06

136 Views

Before getting into example, we should know what LinkedBlockingDeque is. It is implemented by Collection interface and the AbstractQueue class. It provides optional boundaries based on linked nodes.It going to pass memory size to constructor and helps to provide memory wastage in android.This example demonstrate about How to use contains() in android LinkedBlockingDequeStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     In the above code, we have taken text view to show ... Read More

Linear Regression using Python?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

774 Views

Linear regression is one of the simplest standard tool in machine learning to indicate if there is a positive or negative relationship between two variables.Linear regression is one of the few good tools for quick predictive analysis. In this section we are going to use python pandas package to load data and then estimate, interpret and visualize linear regression models.Before we go down further down, let’s discuss what is regression first?What is Regression?Regression is a form of predictive modelling technique which helps in creating a relationship between a dependent and independent variable.Types of RegressionLinear RegressionLogistic RegressionPolynomial RegressionStepwise RegressionWhere is Linear ... Read More

Difference between various Implementations of Python?

AmitDiwan
Updated on 12-Aug-2022 12:08:24

325 Views

Most developers know about python, irrespective of what python is implemented in their system. Therefore, what do I mean by “python”, is it a python the abstract interface? Do we mean CPython, the common Python implementation (not the Cython)?. Or we mean something else entirely? Or we mean Jython or IronPython or PyPy. While the technologies mentioned above are commonly-named and commonly-referenced, however some of them serve completely different purposes. We can think of python as a specification for a language that can be implemented in many different ways. In this tutorial we’ll go through the following implementation of python ... Read More

Working with PDF files in Python?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

1K+ Views

Python is a very versatile language as it provides huge set of libraries to work on different requirements. We all work on Portable Document Format (PDF) files. Python provides different ways to work with pdf files. In this we are going to use python library called PyPDF2 to work with pdf file.PyPDF2 is a pure-python PDF library capable of splitting, merging together, cropping, and transforming the pages of PDF files. It can also add custom data, viewing options, and passwords to PDF files. It can retrieve text and metadata from PDFs as well as merge entire files together.As we can ... Read More

Junk File Organizer in Python?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

573 Views

This might seem very useful for a lazy python programmer who keeps most of the files and folders at one location and sometimes at confused what all files are there and surely he is too lazy to do it manually. So below is a python program to organize or simplify everything in appropriate folder in the single go and remove empty directories.So we have a directory path where lots of files of different types are present (like below) and our program we segregate each file type into their respective folders (like below).Input folder structureDesired OutputFirst create different folders based on ... Read More

Advertisements