(May-03-2019, 08:28 PM)nilamo Wrote:>>> text = '''xxx.xxx.xx.xx ... yyyy ... ... ... ... ... ... xxx.xxx.xx.xx ... yyyy ... ... ... ... ... ... xxx.xxx.xx.xx ... yyyy''' >>> lines = text.split('\n') >>> lines ['xxx.xxx.xx.xx', 'yyyy', '', '', '', '', '', 'xxx.xxx.xx.xx', 'yyyy', '', '', '', '', '', 'xxx.xxx.xx.xx', 'yyyy'] >>> lines = [line for line in lines if line] # remove blanks >>> lines ['xxx.xxx.xx.xx', 'yyyy', 'xxx.xxx.xx.xx', 'yyyy', 'xxx.xxx.xx.xx', 'yyyy'] >>> pairs = [(lines[i-1], lines[i]) for i in range(1, len(lines), 2)] >>> pairs [('xxx.xxx.xx.xx', 'yyyy'), ('xxx.xxx.xx.xx', 'yyyy'), ('xxx.xxx.xx.xx', 'yyyy')] >>> '\n'.join(':'.join(pair) for pair in pairs) 'xxx.xxx.xx.xx:yyyy\nxxx.xxx.xx.xx:yyyy\nxxx.xxx.xx.xx:yyyy' >>> print('\n'.join(':'.join(pair) for pair in pairs)) xxx.xxx.xx.xx:yyyy xxx.xxx.xx.xx:yyyy xxx.xxx.xx.xx:yyyy
This looks very good, but I is from a text file which includes the text.
otherwise I could just do
Quote:x = "xxx.xxx.xx.xx"
y = "yyyy"
print (x + ":" + y)
print ("\n")
Or am I wrong?