0

How to extract a string

how can i extract a string? for instance, extract h2pw3t4n into hhpwwwttttn? for any example like this, how can i do this? pls help me, its so important.

24th Dec 2016, 6:32 PM
Matin Grimes
Matin Grimes - avatar
2 ответов
+ 2
How would you extract h2pw3t4n into ( understanding "from" ) hhpwwwttttn, when the second string don't contain the first? Oo Thanks to having typing these examples strings instead of copy paste, I just understood what you meant ^^ You want compact/uncompact your string with the rule letter followed by number of repetition, isn't it? So, we need to primarly know if the number can be encoded on many digits, or necessary once? It's dertermining for the next steps: the algorithm ^^
24th Dec 2016, 7:15 PM
visph
visph - avatar
+ 1
use this code. store the string to extract in the str variable. extracted string is generated in the exstr variable. works up to 9 character repetitions. str = 'hp3w3tn5' #expected = 'hpppwwwtnnnnn' exstr = '' for c in range(len(str)): if str[c].isdigit(): exstr += str[c-1]*(int(str[c])-1) else: exstr += str[c] print('extracted :', exstr)
26th Jan 2017, 9:09 AM
pravees ivanovich