- 1
Largest consequtive number in a given string in python
input='12jhon345willy3456hans56789kathy' want output as 56789
16 Réponses
+ 5
Kesava N & Xan : UPDATED CODE - pretty and functional now!
Since you asked me to elaborate: Remember, in a list, values are separated by commas. We use a regular expression (regex) to do this. This operation gives a string consisting of numbers and commas. This string is easily converted into a list of integers, dropping all empty values (""). Finally, max() is a built-in function in python to get the highest integer in a list.
The ingenious part is the idea of converting all non-numericals into commas. The rest is pretty standard python stuff.
https://code.sololearn.com/cO1c9BkFveS6/?ref=app
+ 2
Xan - actually, you are totally right! Still, I am glad you like my solution, because I am really happy with it - thanks for appreciating!
+ 1
Why should it print that? You ask for the largest number, you input a number, so this is the largest number by default.
+ 1
Which it should, according to your instructions.
0
input='12jhon345willy3456hans56789kathy'
print(input[22:27])
- 1
I am done upto printing all number and then how to proceed
- 1
how to keep it in a set?
- 1
good but I can't understand that much advance please explain
- 1
I actually stuck here!
- 1
johannes/xan
the code is not working if I change the give to '12jhon345willy3456789hans56789kathy'
- 1
it is printing all
but I want only the largest one!
- 1
:)k
- 1
it again fails showing null when all are numbers
- 1
again fails, when I given input='5656756789'
it should print 56789
but it is printing all the given string