In this article, we will explore different ways to replace duplicate occurrences in a string. Before understanding the solution let's try to understand the problem statement with an example. Consider a string "Ram lives in Hyderabad. Ram is studying in class 10. Ram is the class Monitor of the class." In this string "Ram" appears multiple times we need to replace the duplicate occurrences with 'He', keeping the first occurrence unchanged. Replacing Duplicate Occurrences in a String Following are the multiple ways to replace duplicate occurrences in a string − Using List comprehension ... Read More
Unicode is a standardized character encoding that assigns a unique number to each character in most of the world's writing systems. Unicode separates the code points from the details of the encoding system. This permits a much wider range of characters up to four bytes. The Unicode character set incorporates the entirety of the ASCII character set as the first 127 characters. All ASCII characters have the same code points in both encodings. Techniques to Convert an Integer to a Character Following are the various techniques to convert an integer to a character in Python − ... Read More
The zip() function in Python is used to map elements from multiple iterables at corresponding index positions. It returns an iterator of tuples, where each tuple contains elements from the input iterables at the same index. Suppose the lengths of the input iterables are not the same. In that case, the zip() function will stop pairing once the shortest iterable is exhausted, ignoring any extra elements from the longer iterables. Following is the syntax of the zip() function in Python − zip(iterable1, iterable2) It accepts iterables as a parameter and returns a single iterable. Using zip() with list list ... Read More
We can get console.log output from Chrome with Selenium Python API bindings. We will perform this with the DesiredCapabilities class. We shall enable logging from the browser with DesiredCapabilities.Chrome setting. We have to pass this browser capability to the driver object by passing it as a parameter to the Chrome class. To enable logging we shall set the property goog:loggingPrefs of the browser to 'browser':'ALL'. Syntax Syntax:dc = DesiredCapabilities.CHROME dc['goog:loggingPrefs'] = { 'browser':'ALL' } driver = webdriver.Chrome(desired_capabilities=dc) Example from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities #set browser log dc = DesiredCapabilities.CHROME dc['goog:loggingPrefs'] = { 'browser':'ALL' } driver ... Read More
Python Object Persistence The shelve module in Python's standard library is a simple yet effective tool for persistent data storage when using a relational database solution is not required. The shelf object defined in this module is a dictionary-like object persistently stored in a disk file. This creates a file similar to dbm database on UNIX-like systems. The only string data type can be used as a key in this special dictionary object, whereas any pickable object can serve as value. The shelve module defines three classes as follows − ... Read More
In this article, let's try to find the user's astrological sign for a given data of birth. The user input data will be compared with predefined data ranges for each zodiac sign using programming logic. For example, we can infer that the user is a Taurus if their birthdate falls between April 20 and May 20. The 12 astrological sun signs, also known as zodiac signs, are based on specific periods throughout the year. Each sign corresponds to a particular range of dates, representing distinct personality traits, characteristics, and influences. These sun signs are − ... Read More
In this article, we will explore how to concatenate more than two pandas DataFrames using the pandas and numpy modules. Typically, the pandas.concat() method is used to concatenate multiple data frames. This method allows for concatenation along rows (axis=0) or columns (axis=1), providing flexibility in combining data efficiently. A DataFrame in Python's pandas library is a two-dimensional labeled data structure that is used for data manipulation and analysis. It can handle different data types such as integers, floats, and strings. Each column has a unique label, and each row is labeled with a unique index value, which helps in ... Read More
In this article, let's try to print an inverted star pattern. This pattern involves publishing a series of stars(*) in each line arranged in a descending order. For example, if the N=5 then the output should be − ***** **** *** ** * For printing star (*) patterns frequently, we use for loops. Let's discuss the for loop in Python. Python for loop The for loop in Python provides the ability to loop over the items of any sequence, such as a list, tuple, or string. It performs the same action on each item of the sequence. This ... Read More
The Python division operator is used to divide two integer values and return a quotient. To perform a division operation, we use the / symbol. For example, 16 divided by 4 is written as 16 / 4, which returns 4 as the quotient. Here, 16 is known as divident and 4 is known as divisor. The division operator is one of the arithmetic operator. When we divide an integer by zero, it will raise a ZeroDivisionError exception in Python. For example, if we try to divide 55 by 0 using 55 / 0, it will raise a ZeroDivisionError exception. Types ... Read More
Accessing Values of Dictionary in Python Accessing dictionary items in Python involves retrieving the values associated with specific keys within a dictionary data structure. Dictionaries are composed of key-value pairs, where each key is unique and maps to a corresponding value. Accessing dictionary items allows us to retrieve these values by providing the respective keys. There are various ways to access dictionary items in Python. They include − Using square brackets[] The get() method Using keys() Method Using values() Method ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP