How to split two columns in a table in python -


is the data table

  1 2 3 3 33 34 10 22 11 23 25 26 27 28 ..... Now I should split the data into two columns and merge them into a list. The codes written below do not have single digit numbers but two or three digit numbers.   Myfile = open ("karate.txt", "r") # in the file and myfile.read () in a file for the row: # Read data in the file field = '' Kjoind (line. split ()) # print space field lines = map (brick field) to change the tuple to # partition column # integer data based on the table. Extension (rows)  

The output of this code for the above data

  1 2 3 3 3 3 4 1  
< p> I

  1 2 3 3 33 34 11 23 25 26 27 28 as a required output  

the problem can be essentially divided into two phases: the re-listing ads in numbers as the list again. Field = [] with open ("text.txt") f: fields = [line.split ('') for line f] print field # [(1, 2) (1, 3), (33, 34), (10, 22) ... etc ... flattened = [i Tap] Print flattened # [1, 2, 1, 3, 33, 34, 10, 22, 11, 23, ... ... ...) Line line print: print '\ n'. Include (flattened)

It should print the output you are looking for.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -