Server Side Programming Articles - Page 2138 of 2651

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

Pradeep Elance
Updated on 23-Oct-2019 08:20:20

170 Views

We have to check whether two halves of a string have the same set of characters or not in Python. The frequency of the characters in the two halves must be identical. If the length of the string is odd, ignore the middle and check for the remaining characters. Follow the below steps to write code for the program.Algorithm1. Initialize a string. 2. Initialize an empty dictionary variable alphabets. 3. Initialize a variable mid with length / 2. 4. Write a loop until mid element.    4.1. Initialize the corresponding dictionary item by alphabets[char] with one if it's not initialized. ... Read More

Basic calculator program using Python program

Niharikaa Aitam
Updated on 20-Jun-2025 19:27:44

1K+ Views

In this tutorial, we are going to build a basic calculator in Python. As we all know that a calculator will give six options to the user from which they select one option and we will perform the respective operation. Following are the arithmetic operations that we can perform using a basic calculator - Addition Subtraction Multiplication Division Floor Division Modulo Steps in Developing the Basic Calculator Following are the steps involved in creating a basic calculator in Python - Defining Arithmetic Functions First, we are defining all the arithmetic operations that can be performed by using a ... Read More

Calculate n + nn + nnn + … + n(m times) in Python program

Pradeep Elance
Updated on 23-Oct-2019 08:08:59

2K+ Views

We are going to write a program that calculates the following series in Python. Examine the example inputs and outputs for the program that we are going to write.Input: 34 3 + 33 + 333 + 3333 Output: 3702Input: 5 5 5 + 55 + 555 + 5555 + 55555 Output: 61725So, we will have two numbers, and we have to calculate the sum of the series generated as above. Follow the below steps to achieve the output.Algorithm1. Initialize the number let's say n and m. 2. Initialize a variable with the value n let's say change. 3. Intialize a ... Read More

FuzzyWuzzy Python library

Pradeep Elance
Updated on 23-Oct-2019 08:01:52

741 Views

In this tutorial, we are going to learn about the FuzzyWuzzy Python library. FuzzyBuzzy library is developed to compare to strings. We have other modules like regex, difflib to compare strings. But, FuzzyBuzzy is unique in its way. The methods from this library returns score out of 100 of how much the strings matched instead of true, false or string.To work with the FuzzyWuzzy library, we have to install the fuzzywuzzy and python- Levenshtein. Run the following commands to install them.pip install fuzzywuzzyIf you run the above command, you will the following success message.Collecting fuzzywuzzy Downloading https://files.pythonhosted.org/packages/d8/f1/5a267addb30ab7eaa1beab2 b9323073815da4551076554ecc890a3595ec9/fuzzywuzzy-0.17.0-py2.py3-none-any.whl Installing collected ... Read More

Print anagrams together in Python using List and Dictionary

Pradeep Elance
Updated on 23-Oct-2019 07:52:49

700 Views

In this tutorial, we are going to write a program which finds and prints anagrams using list and dictionary. We have different approaches to every problem. Try to write code without following the tutorial. If you are not able to generate any ideas to write logic, follow the below steps.Algorithm1. Initialize a list of strings. 2. Initialize an empty dictionary. 3. Iterate through the list of strings.    3.1. Sort the string and check if it is present in the dictionary as key or not.       3.1.1. If the sorted string is already present dictionary as a key ... Read More

Print first m multiples of n without using any loop in Python

Pradeep Elance
Updated on 23-Oct-2019 07:48:16

731 Views

In this tutorial, we are going to write a program to find out m multiples of a number n without using loops. For example, we have a number n = 4 and m = 3, the output should be 4, 8, 12. Three multiples of four. Here, the main constraint is not to use loops.We can use the range() function to get the desired output without loops. What is the work of the range() function? range() function returns a range object which we can convert into an iterator.Let's see the syntax of range().Syntaxrange(start, end, step)Algorithmstart - starting number to the ... Read More

Python program to count occurrences of a word in a string

Pradeep Elance
Updated on 23-Oct-2019 07:36:17

4K+ Views

In this tutorial, we are going to write a program that counts the number of times a word occurs in the string. You are given the word and a string, we have to calculate the frequency of the word in the string.Suppose we have a string I am a programmer. I am a student. And the word is. The program that we are going to write will return a number 2 as the word occurs two times in the string.Let's follow the below steps to achieve our goal.Algorithm1. Initialize the string and the word as two variables. 2. Split the string ... Read More

Python program to find the IP Address of the client

Pradeep Elance
Updated on 25-Aug-2023 00:22:01

61K+ Views

In this tutorial, we are going to find the IP address of the client using the socket module in Python. Every laptop, mobile, tablet, etc.., have their unique IP address. We will find it by using the socket module. Let's see the steps to find out the IP address of a device.Algorithm Import the socket module. Get the hostname using the socket.gethostname() method and store it in a variable. Find the IP address by passing the hostname as an argument to the socket.gethostbyname() method and store it in a variable. Print the IP address. Let's write code for the above ... Read More

Sort a list according to the Length of the Elements in Python program

Pradeep Elance
Updated on 23-Oct-2019 06:54:17

6K+ Views

We have a list of strings and our goal is to sort the list based on the length of strings in the list. We have to arrange the strings in ascending order according to their lengths. We can do this using our algorithms or Python built-in method sort() or function sorted() along with a key.Let's take an example to see the output.Input: strings = ["hafeez", "aslan", "honey", "appi"] Output: ["appi", "aslan", "honey", "hafeez"]Let's write our program using sort(key) and sorted(key). Follow the below steps to achieve the desired output using a sorted(key) function.Algorithm1. Initialize the list of strings. 2. Sort ... Read More

Sort Tuples in Increasing Order by any key in Python program

Pradeep Elance
Updated on 23-Oct-2019 06:53:14

211 Views

In this tutorial, we are going to sort a list of tuples in increasing order by nth index key. For example, we have a list of tuples [(2, 2), (1, 2), (3, 1)] then, we have to sort it using 0th index element. The output for that list would be [(1, 2), (2, 2), (3, 1)].We can achieve this by using the sorted method. We have to pass a key while giving the list to the sorted function. Here, the key is the index on which the sorting is based.sorted takes a list and returns that list in ascending order ... Read More

Advertisements