Wednesday, February 22, 2023
HomeSoftware EngineeringLargest Quantity Groupings in String in Python

# Largest Quantity Groupings in String in Python

## The problem#

You might be be given a string that has lowercase letters and numbers. Your activity is to check the quantity groupings and return the biggest quantity. Numbers is not going to have main zeros.

For instance, `resolve("gh12cdy695m1") = 695`, as a result of that is the biggest of all quantity groupings.

## The answer in Python code#

Choice 1:

``````import re
def resolve(s):
return max(map(int,re.findall(r"(d+)", s)))
``````

Choice 2:

``````def resolve(s):
return max(map(int,"".be a part of(" " if x.isalpha() else x for x in s).break up()))
``````

Choice 3:

``````def resolve(s):
i, maxn, L = 0, 0, len(s)
numStart = False
whereas i < L:
if s[i].isdigit():
j = i+1
whereas j<L and s[j].isdigit():
j += 1
if int(s[i:j]) > maxn:
maxn = int(s[i:j])
i = j+1
else:
i += 1
return maxn
``````

## Take a look at instances to validate our resolution#

``````take a look at.it("Primary exams")
take a look at.assert_equals(resolve('gh12cdy695m1'),695)
take a look at.assert_equals(resolve('2ti9iei7qhr5'),9)
take a look at.assert_equals(resolve('vih61w8oohj5'),61)
take a look at.assert_equals(resolve('f7g42g16hcu5'),42)
take a look at.assert_equals(resolve('lu1j8qbbb85'),85)
``````

RELATED ARTICLES