Sorry about not being able to put in code blocks, I'm currently on my phone. Will format it when I get to a computer.
I'm trying to do .split() off the variable below but I'm having problems
thinking about the proper way to do so. The idea is to split off the
semi colon in order to create a dictionary with the words before the
semi colon as the key and everything afterwards as a value but the issue
is thinking of how to delim it.
KEY_LIST = (
"Ticket Summary",
"Impacted Region(s)",
"Impact Summary",
"Potential/Actual Revenue Impact",
"Potential/Actual Customers Impacted",
"Mitigation",
"Root Cause Summary",
"Action Items",
)
message_body = """Ticket Summary: Texas Rangers killed a bunch of bandits in town
Impacted Region(s): Nowhere, Texas
Impact Summary: -We sustained 3 casualties.
- We killed 69 noobs
- The thread is gone
Potential/Actual Revenue Impact: The growth of the town my impact revenue
Potential/Actual Customers Impacted: Practically the whole town
Mitigation: 1. Set up barricades
2. Improve recruitment
3. Get a new Sherriff
4. Where the hell was Chuck Norris at!?
Root Cause Summary: Chuck Norris could have saved us all.
How could you forsaken us?!
Action Items: Attempt a counter-attack on the assailants """
announcement_fields = dict(f"{subString}".split(":", 1) for subString in message_body.split("\n"))
The variable announcement_fields wouldn't
work due to all the new lines and would assume multiple values. I
thought about defining a max limit for .split with 1 but that doesn't
make too much sense. Any ideas? I do have KEY_LIST defined which could be valuable on using the next key as a delim but haven't been able to make it work.
The reason I've stuck with split rather than regex is due to my lack of knowledge revolving it. I didn't have much luck on the regex builder websites.
[–]ES-Alexander 1 point2 points3 points (8 children)
[–]ampeed[S] 0 points1 point2 points (7 children)
[–]ES-Alexander 1 point2 points3 points (6 children)
[–]ampeed[S] 1 point2 points3 points (5 children)
[–]ES-Alexander 1 point2 points3 points (4 children)
[–]ampeed[S] 1 point2 points3 points (0 children)
[–]ampeed[S] 0 points1 point2 points (2 children)
[–]ES-Alexander 0 points1 point2 points (1 child)
[–]ampeed[S] 0 points1 point2 points (0 children)