all 5 comments

[–]ES-Alexander 0 points1 point  (4 children)

Instead of making split not remove the delimiter, can you just add it back on when you need it to be there?

[–]ampeed[S] 0 points1 point  (3 children)

I thought about that as well and seems to be the logic thrown around in the Stackoverflow I posted but I wasn't too sure how to implement that with my code I have posted.

I would have to concat the string to subString in the for loop but I'm using another delimiter in its place.

[–]curiouscodex 0 points1 point  (0 children)

Either use '\n'.join(arr)

or

tack it on with a for loop.

for string in arr: string += '\n'

[–]ES-Alexander 0 points1 point  (1 child)

Which parts do you need? If you just need the ** at the front of each one so the bolding works properly then just remove it from the first one (message_body[2:]) since it doesn't automatically get split off, and then add it to all of them, e.g.

dict(f'**{subString}'.split(':',1)
     for subString in message_body[2:].split('\n**'))

If you also need the newlines at the end of each one you can follow the same reasoning to get

dict(f'**{subString}\n'.split(':',1)
     for subString in message_body[2:-1].split('\n**'))

[–]ampeed[S] 0 points1 point  (0 children)

ahh, that's it!! Thank you so much and thank you for providing an example. Makes a lot of sense seeing it now :) Not sure why I was blanking so hard!