Thursday, 1 April 2021

Python retrieving data from a block of lines containing specific characters and appending relevant data into separate lines

I am trying to create a program which selects specific information from a bulk paste, extract the relevant information and then proceed to paste said information into lines.

Here is some example data;

1.  Track1  03:01
VOC:PersonA 
LYR:LyrcistA
COM:ComposerA
ARR:ArrangerA
ARR:ArrangerB

2.  Track2  04:18
VOC:PersonB
VOC:PersonC
LYR:LyrcistA
LYR:LyrcistC
COM:ComposerA
ARR:ArrangerA

I would like to have the output where the relevant data for the Track1 is grouped together in a single line, with semicolon joining identical information and " - " seperating between others.

LyrcistA  -  ComposerA  -  ArrangerA; ArrangerB
LyrcistA; LyrcistC  -  ComposerA  -  ArrangerA

I have not gotten very far despite my best efforts

while True:
    YodobashiData = input("")
    SplitData = YodobashiData.splitlines();

returns the following

['1.  Track1  03:01']
['VOC:PersonA ']
['LYR:LyrcistA']
['COM:ComposerA']
['ARR:ArrangerA']
['ARR:ArrangerB']
[]
['2.  Track2  04:18']
['VOC:PersonB']
['VOC:PersonC']
['LYR:LyrcistA']
['LYR:LyrcistC']
['COM:ComposerA']
['ARR:ArrangerA']

Whilst I have all the data now in separate lists, I have no idea how to identify and extract the information from the list I need from the ones I do not. Also, it seems I need to have the while loop or else it will only return the first list and nothing else.



from Python retrieving data from a block of lines containing specific characters and appending relevant data into separate lines

No comments:

Post a Comment