I'm quite new to Python regarding string manipulation. I've a field containing some object labels and want to insert text before or behind it. For this I'm using values from a list to search the string for specific values. Once I do this I'm not able to manipulate all found results, only for just one value. I know that strings work differently in Python (immutable), but don't know how to resolve this problem any other way.
objectList = [('Object A','Object B','Object C', 'Object D')]
objectString = '"Object A", "Object B", "Object C", "Object D"'
def transform_toString(objects, old_format):
obj = objects
new_format = old_format
for o in obj:
position = new_format.find(str(o))
new_format = new_format[:position] + ' found' + new_format[position:]
return new_format
transformed_string = transform_toString(objectList, objectString)
This results in the following output:
"Object A", "Object B", "Object C", "Object D found"
How can I achieve the following output?
"Object A found", "Object B found", "Object C found", "Object D found"
ObjectListlist of length 1 which does hold 4-tuple