Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Vrundesha Joshi
218 articles
ipaddress - IPv4/IPv6 manipulation library in Python
Internet Protocol is currently in the process of moving from version 4 to version 6. This is necessitated because version 4 doesn't provide enough addresses to handle the increasing number of devices with direct connections to the internet. An IPv4 address is composed of 32 bits, represented into four eight-bit groups called "octets". This is a "dotted decimal" format where each eight-bit octet can have a decimal value 0 to 255. For example: 192.168.1.1 IPv4 address with CIDR notation: 192.168.1.1/24 where 24 means first three octets identify the network and last octet identifies node. An IPv6 ...
Read Morehtml.parser — Simple HTML and XHTML parser in Python
The html.parser module in Python's standard library provides the HTMLParser class for parsing HTML and XHTML documents. This class contains handler methods that can identify tags, data, comments, and other HTML elements. To use HTMLParser, create a subclass that inherits from HTMLParser and override specific handler methods to process different HTML elements. Basic HTMLParser Setup Here's the basic structure for creating a custom HTML parser ? from html.parser import HTMLParser class MyParser(HTMLParser): pass parser = MyParser() parser.feed('') Handling Start Tags The handle_starttag(tag, attrs) method is called ...
Read MoreBisect - Array bisection algorithm in Python
The bisect module provides efficient algorithms for maintaining sorted lists. Instead of sorting after every insertion, it uses binary search to find the correct position quickly. This is much more efficient for frequent insertions into large sorted lists. bisect_left() Finds the insertion point for a value to maintain sorted order. If the value already exists, it returns the position before any existing entries ? import bisect nums = [10, 20, 30, 40, 50] position = bisect.bisect_left(nums, 25) print(f"Insert 25 at position: {position}") # Insert to verify nums.insert(position, 25) print(f"Updated list: {nums}") ...
Read MorePython Input Methods for Competitive Programming?
In competitive programming, efficient input/output methods can significantly improve your solution's performance. Python offers several approaches for reading input, each with different speed characteristics. Let's explore various I/O methods using a simple example: reading four numbers a, b, c, d and printing their product. Basic Input Methods Using List Comprehension This method uses list comprehension to convert input strings to integers − a, b, c, d = [int(x) for x in input().split()] print(a * b * c * d) Using map() Function The map() function provides a cleaner syntax for type ...
Read MoreWorking with PDF files in Python?
Python provides excellent libraries for working with PDF files. PyPDF2 is a popular pure-Python library that can split, merge, crop, and transform PDF pages. It can also extract text, metadata, and add security features to PDF files. Installation Install PyPDF2 using pip ? pip install PyPDF2 Verify the installation ? import PyPDF2 print("PyPDF2 imported successfully!") PyPDF2 imported successfully! Extracting PDF Metadata You can extract useful information like author, title, subject, and page count from any PDF file ? from PyPDF2 import PdfFileReader def ...
Read MoreCalculate geographic coordinates of places using google geocoding API in Python?
To get the geographic coordinates (longitude and latitude) of any place, we can use the Google Maps Geocoding API. This API converts addresses into geographic coordinates and provides detailed location information. Requirements To get the coordinates of a place, you need a Google Geocoding API key. You can get it from the official Google documentation: https://developers.google.com/maps/documentation/geocoding/get-api-key Apart from the API key, we need the following Python modules − requests module (to fetch the coordinates from API) json module (for JSON data conversion) Basic Implementation Here's ...
Read MoreWebCam Motion Detector program in Python ?
A WebCam Motion Detector analyzes images from your webcam to detect movement and logs the time intervals when motion occurs. This program uses computer vision techniques to compare frames and identify changes. Required Libraries Install the required libraries using pip ? pip install opencv-python pandas How Motion Detection Works Background Frame Compare Current Frame ...
Read MoreConway's Game Of Life using Python?
Conway's Game of Life is a cellular automaton created by British mathematician John Conway in 1970. It simulates the evolution of a colony of biological organisms on a two-dimensional grid consisting of "living" and "dead" cells. Rules of Conway's Game of Life The game follows four simple rules that determine whether a cell lives or dies in the next generation ? Overpopulation: A living cell dies if it has more than three living neighbors Survival: A living cell survives if it has two or three living neighbors Underpopulation: A living ...
Read MoreRun Python script from Node.js using child process spawn() method?
Node.js and Python are two popular languages among developers. While Node.js excels at web development, Python provides extensive libraries for scientific computing, AI, and machine learning. Fortunately, we can combine both by running Python scripts from Node.js using the child_process module. The spawn() method creates a child process to run Python scripts in the background and stream results back to Node.js in real-time. Creating the Python Script First, let's create a Python script that accepts command-line arguments and outputs messages over time − # myscript.py import sys, getopt, time def main(argv): ...
Read MorePrint with your own font using Python?
In Python, you can display text in creative ASCII art styles using the pyfiglet module. This library converts regular strings into artistic text representations using various fonts. Installation First, install pyfiglet using pip − pip install pyfiglet Basic Usage The simplest way to create ASCII art text is using the figlet_format() function − import pyfiglet ascii_banner = pyfiglet.figlet_format("Hello, Python") print(ascii_banner) _ _ _ _ ____ ...
Read More