python merge lines
I have to use python because it will be part of existing python code.
Example input Quote:
Quote:
Below is the monstrosity that I tried and it fails miserably. In the below example 'regressionList' corresponds to the above sample input. Code:
def writeTest(regressionList): |
Use a defaultdict where the key is the first column and the default value is an empty list.
|
Quote:
|
This looks suspiciously like a job interview question. But whatever:
Code:
import collections |
That works just as advertised.
Not an interview question - but the concern is understood. It is probably clear that I would never qualify for even an entry level python programming position. I work for a semiconductor design company and 95% of my work consist of SKILL programming for pcell development. Python was needed for this particular project to extract data from an excel file. SKILL has no built in functions for handling excel spreadsheets so I decided to use python to extract the required data from the excel file and write the result to a csv file. The final csv file would look like this. Quote:
|
I did notice one small glitch.
There should be a space between 'devType' and the first x1,y1, or z1, not a colon. I will attempt to modify the code to meet that spec. Will let you know how it goes. |
Modified # column 2 to add a space after the input.
original: new_rows[original_row[0]].append(original_row[1]) change: new_rows[original_row[0]].append(original_row[1]+" ") Modified # column 2 to place the colon after the input. original: new_rows[original_row[0]][1] += ":" + original_row[2] change: new_rows[original_row[0]][1] += original_row[2] + ":" The final result still has a trailing ":" that is not needed. Quote:
|
I can't believe you manually tried to write a diff.
|
All times are GMT -5. The time now is 03:23 AM. |