473,473 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

split the list

1 New Member
hi,
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;gaussian_top.sh;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']
  2.  
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']
  4.  
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
1 1353
bvdet
2,851 Recognized Expert Moderator Specialist
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

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

Similar topics

5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
3
by: Matthew Walsh | last post by:
Whats wrong with the following code? using pythonWin I get the following error: Traceback (most recent call last): File "C:\Python23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",...
5
by: Marie | last post by:
TblOptions OptionID Option There are 7 option records. If I have two subforms, how do I list the first 4 options in the first subform and the last 3 options in the second subform? Thank...
1
by: Booser | last post by:
// Merge sort using circular linked list // By Jason Hall <booser108@yahoo.com> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> //#define debug
11
by: Neo | last post by:
Hi Frns, Could U plz. suggest me how can i reverse a link list (without recursion)??? here is my code (incomplete): #include<stdio.h>
4
by: MJ | last post by:
Hi I have written a prog for reversing a linked list I have used globle pointer Can any one tell me how I can modify this prog so that I dont have to use extra pointer Head1. When I reverse a LL...
6
by: rh0dium | last post by:
Hi all, I am having a bit of difficulty in figuring out an efficient way to split up my data and identify the unique pieces of it. list= Now I want to split each item up on the "_" and...
1
by: maxtoroq | last post by:
I know how to work the .FindAll method of the List class, but is there a way to split a list into 2 lists, one containing all the items that match a certain criteria and one that doesn't?
9
by: incredible | last post by:
how to sort link list of string
36
by: pereges | last post by:
Hi, I am wondering which of the two data structures (link list or array) would be better in my situation. I have to create a list of rays for my ray tracing program. the data structure of ray...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.