In code now it will overwrite all values and only save last.
I would do it something like this,making a replace_dict first then loop over and replace.
I would do it something like this,making a replace_dict first then loop over and replace.
# mapp1.py # Your .csv output append to list,can also make it dict on fly lst = [ ['-nrdbc', 'n3DeleteBearerCommand'], ['-nrrc', 'n3ContextRsp'], ] # Make it to a dictionary replace_dict = {key: value for key, value in lst} input_string = "gsh modify_gtp_v2 -nrrc 3 -trac 3 -nrds 2 -trds 5 -nrdbc 2" words = input_string.split() output_words = [] for word in words: if word in replace_dict: output_words.append(replace_dict[word]) else: output_words.append(word) output_string = " ".join(output_words) print(output_string)Test.
λ python -i mapp1.py gsh modify_gtp_v2 n3ContextRsp 3 -trac 3 -nrds 2 -trds 5 n3DeleteBearerCommand 2 >>> replace_dict {'-nrdbc': 'n3DeleteBearerCommand', '-nrrc': 'n3ContextRsp'} >>> # Made from >>> lst [['-nrdbc', 'n3DeleteBearerCommand'], ['-nrrc', 'n3ContextRsp']]