So i have this code where i'm creating a list with substrings: '''
string = "|01|12345|TEXT1|TEXT2|"
x = string.count("|")
if string.count('|') == 3:
subst = string.strip('|').split('|')
print(substr)
else:
substr = string.strip('|').split('|')
print(substr)
'''
Outcome:
'''
['01', '12345', 'TEXT1', 'TEXT2']
'''
However, i want to print all the substrings that the outcome is this:
'''
[LAS|01|G12345|TEXT1|TEXT2|<CR>|]
'''
I know i can just do:
'''
print("[LAS|" + substr[0] + "|G" + substr[1] + "|" + substr[2] + "|" + substr[3] + "|<CR>|]")
'''
But this is hardcoded, what if my the string that i get makes way more substrings? I do not want to use allot of if statements, if the count of ('|') == 4, == 5, == 6 etc.
How do i make sure that what i print contains all the substrings. And has a pipe symbol (|) in between every substring.
Thanks,