Found 10476 Articles for Python

Check if both halves of the string have same set of characters in Python

Niharikaa Aitam
Updated on 20-Jun-2025 19:29:52

315 Views

In Python, a string is one of the data structures that is a sequence of characters enclosed within single quotes '' or double quotes "". It is immutable, i.e., once a string is created, it cannot be changed. When we want to check if both halves of the string have the same set of characters in Python, we can follow the steps below - First, based on the length of the string, we have to split the string into two halves. Next, convert each half into a set of characters using set() function. Finally, compare the two sets using ... Read More

Check for balanced parentheses in Python

Akshitha Mote
Updated on 22-Jan-2025 13:33:51

984 Views

In this article, we will solve the problem of checking balanced parentheses. Let's understand the problem statement, The following are the conditions for balanced parentheses − Every opening parenthesis has a corresponding closing parentheses. Parentheses should be closed in the correct order. For example, "{[()]}" is a balanced parenthesis. condiser the same example with different arrangment "{([})]" which is unbalanced parantheses. Checking parentheses Using 'list' and 'for' loop list is one of the built-in data types in Python. A Python list is a sequence of comma-separated items, enclosed ... Read More

Unit Testing in Python Program using Unittest

Pavitra
Updated on 27-Sep-2019 11:30:13

187 Views

In this article, we will learn about the fundamentals of software testing by the help of unittest module available in Python 3.x. Or earlier. It allows automation, sharing of the setup and exit code for tests, and independent tests for every framework.In unit test, we use a wide variety of object oriented concepts. We will be discussing some majorly used concepts here.Testcase − It is response specific base class in accordance with a given set of inputs. We use base class of unittest i.e. “TestCase” to implement this operation.Testsuite − It is used to club test cases together and execute ... Read More

Twitter Sentiment Analysis using Python Program

Pavitra
Updated on 16-May-2022 12:23:58

482 Views

In this article, we will be learning about the twitter sentimental analysis. We will register for twitter oAuth API, install all the dependencies and finally write our sentimental analyzer script.An API(Application programming interface) is a gateway that allows you to access some servers(Twitter) internal functionality.The prerequisite is that we have a twitter account set up with verified phone number.After this, we visit the twitters website and tap on the create a new app icon. Now we fill all the credentials i.e. name and accept the developer agreement and finally click on create.Now our app is created , on the top ... Read More

Python program to print odd numbers in a list

Pavitra
Updated on 04-Jul-2020 13:00:29

3K+ Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a list iterable as input, we need to display odd numbers in the given iterable.Here we will be discussing three different approaches to solve this problem.Approach 1 − Using enhanced for loopExamplelist1 = [11, 23, 45, 23, 64, 22, 11, 24] # iteration for num in list1:    # check    if num % 2 != 0:       print(num, end = " ")Output11, 23, 45, 23, 11Approach 2 − Using lambda & filter functionsExample Live Demolist1 = [11, 23, 45, 23, ... Read More

Python Program to Print Numbers in an Interval

Pavitra
Updated on 27-Sep-2019 11:06:50

520 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven the starting and ending range of an interval. We need to print all the numbers in the interval given.A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.There are two for loops, first for loop is for getting the numbers in the interval and second loop for the checking whether the number is prime or not.Now let’s see the implementation.Example Live Demostart = 10 end = 29 for val in range(start, end + ... Read More

Python program to print negative numbers in a list

Pavitra
Updated on 04-Jul-2020 12:54:55

761 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a list iterable, we need to print all the negative numbers in the list.Here we will be discussing three approaches for the given problem statement.Approach 1 − Using enhanced for loopExamplelist1 = [-11, 23, -45, 23, -64, -22, -11, 24] # iteration for num in list1:    # check    if num < 0:       print(num, end = " ")Output-11 -45 -64 -22 -11Approach 2 − Using filter & lambda functionExample Live Demolist1 = [-11, 23, -45, 23, -64, -22, -11, ... Read More

Python program to print even numbers in a list

Harshit Sachan
Updated on 13-Oct-2022 12:03:38

13K+ Views

Python Programming Language is one of the most efficient and user-friendly programming language and have endless uses and applications. Lists declared in Python are analogous to dynamically sized arrays in other programming languages (vector in C++ and ArrayList in Java). A list is simply a collection of items enclosed by [] and separated by commas. In this tutorial, we will learn about the solution and approach to find out all even numbers in a given list using Python. List is one of the most fundamental data structures in python. They are widely used and they store similar contiguous data. A ... Read More

Python program to print even length words in a string

Harshit Sachan
Updated on 13-Oct-2022 11:58:05

6K+ Views

In Python Programming Language, Length is the concept of calculating the entire range of the string that begins from the first character of the string till the last character of the string. Printing and calculating even length in a string is a basic exercise in the programing language. In this tutorial, we will learn about the solution and approach to find out all words in a string having even length. A number is considered odd if it divides by 2 evenly, i.e. leaving no remainder. This property should hold for the length of the words we need. So the ... Read More

Python program to print all odd numbers in a range

Pavitra
Updated on 27-Sep-2019 08:05:27

952 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a range, we need to print all the odd numbers in the given range.The brute-force approach is discussed below −Here we apply a range-based for loop which provides all the integers available in the input interval.After this, a check condition for odd numbers is applied to filter all the even numbers.This approach takes O(n) + constant time of comparison.Now let’s see the implementation below −Examplestart, end = 10, 29 # iteration for num in range(start, end + 1):    # check   ... Read More

Advertisements