python – Can I split this string by word without importing regex?
I have a very long string that repeats values. I want to split the string into a list where the value equals “shiftdate”. Can this be achieved without importing regex?
sampleString = "shiftdate_154_04-01-2024@scode_154_AAA@shiftstart_154_0000@shiftend_154_2400@eligdate_154_04-01-2024@forfdate_154_04-01-2024@payoutdate_154_04-01-2024@payoutscode_154_AA59@schedhol_154_Y@scheddate_154_@autosched_154_Y@autoscheddate_154_@shiftdate_155_@scode_155_AACT@shiftstart_155_0000@shiftend_155_2400@eligdate_155_@forfdate_155_@payoutdate_155_@payoutscode_155_155_AA59@schedhol_155_ @scheddate_155_@autosched_155_ @autosched_155date_155_"
I want to split the string into a list where “shiftdate” begins. So final result would be
list = [
"shiftdate_154_04-01-2024@scode_154_AAA@shiftstart_154_0000@shiftend_154_2400@eligdate_154_04-01-2024@forfdate_154_04-01-2024@payoutdate_154_04-01-2024@payoutscode_154_AA59@schedhol_154_Y@scheddate_154_@autosched_154_Y@autoscheddate_154_@",
"shiftdate_155_@scode_155_AACT@shiftstart_155_0000@shiftend_155_2400@eligdate_155_@forfdate_155_@payoutdate_155_@payoutscode_155_155_AA59@schedhol_155_ @scheddate_155_@autosched_155_ @autosched_155date_155_"
]
I tried using the split
function but have not been successful. It is removing the text/value I want to start at. What am I forgetting to use in the python library that can help solve this issue? Would it be a good idea for me to insert a comma before the start value and use split from there?
Read more here: Source link