Hi I am relatively new to Python and have been trying different solutions , however cannot find any easy way to do this.
So I have a string which looks like this:
str = '-host hostname -port portnum -app appname -l licensename -service sname'
I want only to extract the -l licensename where license name could be different depending on apps and replace this with -l newlicensename.
I tried using replace, but wont suit my needs as different apps use different license names so cannot do for bulk.
Another option I tried was to use join and zip functions like below:
output = [' '.join((first, second)) for first, second in zip(words, secondwords)]
to select only the first two sections of the string separately in a list, however, this did not work as well as the output was:
[u'-host hostname', u'hostname -port', u'-port portnum', u'portnum -app', u'-app appname', u'appname -service', u'-service sname', u'-l licencename , 'u'sname -l']
instead of the expected:
['-host hostname', '-port portnum', '-app appname', '-l licencename','-service sname']
Any suggestions on the best way to do this?