- 1

Largest consequtive number in a given string in python

input='12jhon345willy3456hans56789kathy' want output as 56789

25th Apr 2018, 5:57 PM
Kesava N
Kesava N - avatar
16 Answers
+ 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
25th Apr 2018, 6:45 PM
Johannes
Johannes - avatar
+ 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!
25th Apr 2018, 6:50 PM
Johannes
Johannes - avatar
+ 1
Why should it print that? You ask for the largest number, you input a number, so this is the largest number by default.
27th Apr 2018, 8:17 PM
Johannes
Johannes - avatar
+ 1
Which it should, according to your instructions.
27th Apr 2018, 8:17 PM
Johannes
Johannes - avatar
0
input='12jhon345willy3456hans56789kathy' print(input[22:27])
25th Apr 2018, 6:29 PM
📈SmileGoodHope📈
📈SmileGoodHope📈 - avatar
- 1
I am done upto printing all number and then how to proceed
25th Apr 2018, 6:37 PM
Kesava N
Kesava N - avatar
- 1
how to keep it in a set?
25th Apr 2018, 6:39 PM
Kesava N
Kesava N - avatar
- 1
good but I can't understand that much advance please explain
25th Apr 2018, 6:47 PM
Kesava N
Kesava N - avatar
25th Apr 2018, 7:03 PM
Kesava N
Kesava N - avatar
- 1
I actually stuck here!
25th Apr 2018, 7:03 PM
Kesava N
Kesava N - avatar
- 1
johannes/xan the code is not working if I change the give to '12jhon345willy3456789hans56789kathy'
25th Apr 2018, 7:17 PM
Kesava N
Kesava N - avatar
- 1
it is printing all but I want only the largest one!
25th Apr 2018, 7:32 PM
Kesava N
Kesava N - avatar
- 1
:)k
25th Apr 2018, 7:35 PM
Kesava N
Kesava N - avatar
25th Apr 2018, 7:43 PM
Kesava N
Kesava N - avatar
- 1
it again fails showing null when all are numbers
25th Apr 2018, 7:44 PM
Kesava N
Kesava N - avatar
- 1
again fails, when I given input='5656756789' it should print 56789 but it is printing all the given string
25th Apr 2018, 8:05 PM
Kesava N
Kesava N - avatar