I am pretty sure there would be more elegant, in-place solutions but here is a quick solution to your problem. Should be OK if your sequence
dictionary is not way too large.
names_tupleseq_names = zip(data['old_name'], data['new_name']) # brings together old and new names in tuples
new_dictrenamed_sequence = {}
for i in names_tupleseq_names:
new_dict[i[1]]renamed_sequence[i[1]] = sequence[i[0]]
new_dictrenamed_sequence
EDIT: The section below is not quite accurate, please see the comments below.
And regarding your comment:
I tried to replace the old names with a for loop, but it was imposible to do it.
You are not supposed to loop over and at the same time modify an element at the same time anyway (there might be side effects that you would not think of), hence a brand new dictionary in my code.