Table of Contents
Introduction
The task is to find the maximum number from the alphanumeric string.
Program
import re def max_ele(ip_str): ele = map(int,re.findall("\d+",ip_str)) return max(ele) ip_str = input("Enter the string: ") print("The maximum number in the string {0} is {1}". format(ip_str, max_ele(ip_str)))
Output
Explanation
In the above python code the steps followed are:
- We have used re.findall() method to extract the numeric value from the given string. The re.findall() method takes expression and string as the argument. We passed expression as ‘\d+’, it returns one or more digit values.
- We have used map() function to convert the numbers to integer.
- And returned the max element using max() function.
0 Comments