Remove zeros from an IP address. 

In this program, we will take a string of IP address as input and remove zeros from an IP address. 

Steps to solve the program
  1. Take a string of an IP address as input.
  2. Import re library.
  3. Remove zeros from the IP address using re.sub().
  4. Print the output.
				
					#Importing re
import re

#Input string
str1 = "289.03.02.054"

string = re.sub('\.[0]*', '.', str1)

#Printing output
print(string)
				
			

Output :

				
					289.3.2.54
				
			

calculate the sum of digits of a given string.

find the maximum length of consecutive 0’s in a given binary string

Leave a Comment