You are given three strings S, A and B. You have to replace every sub−string of S equal to A with B and every sub−string of S equal to B with A. There is a possibility that two or more sub−strings matching A or B overlap. To avoid this confusion about the situation, you have to find the leftmost sub−string that matches A or B, replace it, and then continue with the rest of the string. Input S = “aab”, A = “aa”, B = “bb” Output “bbb” Match the first two characters with A and ... Read More
A particular sort of chart that is frequently used to show the steps in a process is a funnel chart and it is named so due to its funnel-like design, which has a broad top and a small bottom. The chart sections are divided into stages, and the quantity of things that move through each stage is indicated by the size of each section. We'll learn how to make a funnel chart in Pygal, a Python framework for making interactive charts, in this tutorial. Installation and Syntax Pygal must first be installed using pip before it can be used so ... Read More
Functional programming uses the idea of functors to help programmers create more modular, reusable, and reasonable code. They are a means to enclose a value or a function in an object and then manipulate that object without altering the original object. Functors are a potent tool for writing modular, reusable code in Python and may be implemented using classes. Syntax As Python functors are implemented using classes, a key component of the language, there is no special installation needed. Just build a class with an init method that accepts the original value or function as a parameter and a call ... Read More
You are given a string 'str' that contains both uppercase and lowercase letters. Any lowercase character can be changed to an uppercase character and vice versa in a single action. The goal is to print the least possible instances of this process that are necessary to produce a string containing at least one lowercase character, followed by at least one uppercase character. Input Output Scenarios First possible solution: the first 4 characters can be converted to uppercase characters i.e. “TUTORial” with 4 operations. Input str = “tutoRial” Output 1 Second possible solution: the third character ... Read More
Functions that take parameters in the form of variable-length key-value pairs can be defined in Python. This enables more dynamic and versatile functions that can handle a variety of inputs. When a function has to be able to handle arbitrary or optional parameters, this feature is frequently employed. Learn how to use the **kwargs and ** syntax to send a function a variable number of arguments in this technical article. Syntax The **kwargs syntax indicates that the function accepts an arbitrary number of keyword arguments, which are passed in as a dictionary. def function_name(**kwargs): # code block ... Read More
Function overloading is a popular concept in object-oriented programming where functions can have the same name but different parameters. This enables the developer to write functions that can perform different operations based on the input parameters. However, Python doesn't support function overloading as traditionally seen in other object-oriented languages such as Java or C++. Fortunately, the singledispatch function from the functools module provides a solution for Python developers to implement function overloading. Syntax The functools module is part of the Python standard library and doesn't require any installation. To use the singledispatch function, import it from the functools module − ... Read More
Welcome to this blog post where we will be discussing the implementation of a fun game called Flip! using Python. Flip! is a game that involves flipping over tiles on a 4x4 grid to reveal their color. The objective of the game is to flip over all the tiles while making as few moves as possible. In this post, we will go through the implementation of the game using Python and explain the different components of the code. Syntax The following packages are used in this code − itertools − This package provides functions to iterate over collections in ... Read More
You are given two strings A and B, the task is to convert from string A to string B, if possible. You are allowed to perform only one operation that is to put any character from A and insert it at front. Check if it’s possible to convert the string. If yes, then output minimum number of operations required for transformation. Input output Scenarios Assume we have two strings A and B with values "ABD" and "BAD" respectively the operation need to take to convert the first string to the latter is 1 which is swapping the first two characters. ... Read More
One of the biggest online markets in India is Flipkart, where shoppers can buy everything from gadgets to apparel. Any commercial service must examine the tone of the evaluations in order to enhance their services as a result of the growing number of consumers and their feedback. To detect whether a text exhibits a positive, negative, or neutral attitude, Sentiment Analysis is a Natural Language Processing approach which we will be examining using Python to conduct sentiment analysis on product reviews in this technical blog. Installation and Syntax To perform sentiment analysis on Flipkart reviews, we will need to install ... Read More
Data Definition Language(DDL) is used for describing data and its relationship in a database. It is also used to define the database schema. The commands only affect the database structure and not the data. The main DDL commands are create, alter, drop and truncate. Create Statement It is used to create a database or table. While creating the table, we specify table_name, column_name followed by data_types(int, float, varchar, etc) and constraints(primary key, not null, etc) Syntax CREATE TABLE table_name ( column1 datatype, column2 datatype, ..... ) Example In this ... Read More