It’s pretty hard to explain but here’s my issue..
sampleList = ['_ This is an item.','__ This is also an item']
I’m trying to take sampleList and find if _ occurs ONLY in the first character line, replace it with #, and then if __ occurs, replace with &.
It’s a bit hard to understand even for myself.
Basically if I have a list, I want it to work through the list, only find the FIRST instance of a possible dict and replace it with the corresponding value. And then return that entire list..
EDIT:
Sorry if I wasn’t descriptive enough..
dictarray = {
'_':'&',
'__':'*#',
'____':'*$(@'
}
sampleList = ['_ This is an item.','__ This is also an item','_ just another _ item','____ and this last one']
output:
sampleList = ['& This is an item.','*# This is also an item','& just another _ item','*$(@ and this last one']
I need to be able to capture if the key is found at the beginning of the item, if so, change it out for the value.
produces:
Here I’ve massaged the dictarray to order the substitution longest first, so that shorter prefixes don’t preclude longer ones.