By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,641 Members | 2,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,641 IT Pros & Developers. It's quick & easy.

split the list

P: 1
I have a list which is read from a file
Expand|Select|Wrap|Line Numbers
  1. ['48998.tyrone-cluster;gic1_nwgs;mbupi;18:45:44;R;qp32\n', '48999.tyrone-cluster;gic2_nwgs;mbupi;0;Q;batch\n', '49005.tyrone-cluster;...01R-1849-01_2;mcbkss;00:44:23;R;qp32\n', '49032.tyrone-cluster;;chemraja;0;Q;qp32\n', '49047.tyrone-cluster;jet_egrid;asevelt;312:33:0;R;qp128\n', '49052.tyrone-cluster;case3sqTS1e-4;mecvamsi;0;Q;qp32\n', '49053.tyrone-cluster;...01R-1850-01_1;mcbkss;0;Q;batch\n', '49054.tyrone-cluster;...01R-1850-01_2;mcbkss;0;Q;batch\n']
i need to get the output in the form
Expand|Select|Wrap|Line Numbers
  1. ['48998','18:45:44','R','qp32']
  2. ['48999','0','Q','batch']
  3. ['49005','00:44:23','R','qp32']
and each of this list is written into a file job.txt
till now i have tried split(".") but could not get the required output
Mar 4 '15 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 2.5K+
P: 2,851
It appears your data is consistently formatted. A for loop or nested list comprehension should do it.
Expand|Select|Wrap|Line Numbers
  1. parsed_data = [[item[0].split(".")[0], item[3], item[4], item[5].strip()]
  2.                for item in [s.split(";") for s in data]]
Expand|Select|Wrap|Line Numbers
  1. >>> print "\n".join([",".join(item) for item in parsed_data])
  2. 48998,18:45:44,R,qp32
  3. 48999,0,Q,batch
  4. 49005,00:44:23,R,qp32
  5. 49032,0,Q,qp32
  6. 49047,312:33:0,R,qp128
  7. 49052,0,Q,qp32
  8. 49053,0,Q,batch
  9. 49054,0,Q,batch
  10. >>> 
Mar 4 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.