python - Passing textfile and Creating new Tuple when there is space -


I have a text file that I would like to pass on to Python and a new location every time to get a new location For example, I want to create a tipple, for example, I have the following file

  land, 3-4, -2 4,3 ocean, 5 3-4-6, 5 5 6   

My aim is to prepare a topless for the first one, then when we build another tube for the second position, until we reach the final ,

Not the most elegant solution The desired output is quite weird. File_contents.split

  fp = open ('test.txt', 'r') file_contents = fp.read () results = [] \ n \ n '): Split = ','. (Split.split ('\ n')) split = '' .join (split.split ('')) split = split.split (',') range for x (0, lane (division) - 1, 2): if x == 0: result .append (split [x]) result.append ((0, int (split [x + 1])) else: result.append ((int (split [x] ]), int (split [x + 1]) print result   

output:

  ['land', (0, 3), ( -4, -2), (4, 3), 'Ocean', (0, 5), (3, 4), (-6, 5), (5, 6)]    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -