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
Python Articles
Page 700 of 855
Internal working of the list in Python
In this tutorial, we will learn about the internal working of lists in Python. We will explore how Python manages list objects in memory and examine the frame formation when we execute different list operations step by step. List Initialization When we create a list with elements, Python allocates memory and creates a list object ? lis = [1, 2, 3, 4] print(lis) print(f"List ID: {id(lis)}") print(f"List length: {len(lis)}") [1, 2, 3, 4] List ID: 140712234567808 List length: 4 Global Frame lis ...
Read MoreInteresting Python Implementation for Next Greater Elements
In this article, we will learn how to find the Next Greater Element for each element in an array. The Next Greater Element is the first larger element that appears to the right of the current element in the array. Problem Statement Given an array of integers, we need to find the Next Greater Element for every element. For elements that don't have a greater element on their right side, we return -1. Example Input and Output For the array [12, 1, 2, 3] − 12 → -1 (no element greater than 12 ...
Read Moreissubset() function in Python
In this article, we will learn the implementation and usage of issubset() function available in the Python Standard Library. The issubset() method returns boolean True when all elements of a set are present in another set (passed as an argument) otherwise, it returns boolean False. In the figure given below B is a subset of A. When A & B are identical sets, A is considered a proper subset of B, meaning both sets contain the same elements. Set A ...
Read MoreInput/Output from external file in C/C++, Java and Python for Competitive Programming
In competitive programming, reading input from files and writing output to files is essential for testing solutions locally. This article covers file I/O techniques in Python, Java, and C/C++. Python I/O from File Python uses the sys module to redirect standard input and output to files. This approach allows you to use regular input() and print() functions while reading from and writing to files ? Example import sys # Redirect input from file sys.stdin = open('input.txt', 'r') # Redirect output to file sys.stdout = open('output.txt', 'w') # Now use regular ...
Read MoreIDE for Python programming on Windows
Choosing the right IDE can significantly improve your Python development experience on Windows. Let's explore the most popular Python IDEs, each offering unique features for different development needs. PyCharm PyCharm is a professional IDE developed by JetBrains, offering comprehensive Python development tools ? Interactive Python Console: Built-in console for testing code snippets Web Framework Support: Django, Flask, and other frameworks integration Intelligent Code Refactoring: Automated code improvement suggestions Advanced Debugging: Visual debugger with breakpoints and variable inspection Version Control Integration: Git, ...
Read MoreInteresting facts about strings in Python
Python strings have several fascinating characteristics that make them unique among programming languages. Let's explore four key features: immutability, escape sequence detection, direct slicing, and indexed access. Immutability Python strings are immutable, meaning once created, their content cannot be modified. You can only read from strings, not change individual characters ? text = 'Tutorials Point' print(text) # This will raise an error try: text[0] = 't' except TypeError as e: print(f"Error: {e}") Tutorials Point Error: 'str' object does not support item assignment ...
Read MoreImplement IsNumber() function in Python
In this article, we will learn how to implement an isNumber() function in Python. This custom function checks whether a given string represents a valid number and returns True or False accordingly. The function uses exception handling with try and except statements to determine if a string can be converted to a number. This approach is efficient because Python's built-in conversion functions will raise a ValueError if the string is not a valid number. Input String Check Negative ...
Read MoreWhat makes Python Cool?
Python is loved by developers worldwide for its elegant syntax and powerful built-in features. In this article, we will explore the key features that make Python cool and different from other programming languages. The Zen of Python Python's philosophy is captured in "The Zen of Python", which you can access by importing the this module ? import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. The flat is better than nested. Sparse is ...
Read MorePython vulnerability in input() function
The input() function in Python 2.x had a serious security vulnerability that could allow code injection attacks. Unlike Python 3.x, the Python 2.x input() function evaluates user input as Python code, while raw_input() safely returns a string. Difference Between input() and raw_input() in Python 2.x Let's examine how these functions handle different data types in Python 2.x ? # Python 2.x behavior (DO NOT RUN - for illustration only) # Input Given: "hello" (string) str1 = raw_input("Output of raw_input() function: ") print type(str1) # Always returns str2 = input("Output of input() function: ") ...
Read MoreUsing Counter() in Python 3.x. to find minimum character removal to make two strings anagram
In this article, we will learn how to find the minimum number of character removals needed to make two strings anagrams using Python's Counter() function. Two strings are anagrams when they contain the same characters with the same frequencies, regardless of order. The Counter() method is available in Python's collections module and provides an efficient way to count character frequencies in strings. What are Anagrams? Two strings are anagrams if they contain the same characters with identical frequencies. For example: "listen" and "silent" are anagrams "hello" and "world" are not anagrams Algorithm ...
Read More