Skip to main content
added 20 characters in body
Source Link
haci
  • 4.2k
  • 1
  • 7
  • 28

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.

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_tuple = zip(data['old_name'], data['new_name']) # brings together old and new names in tuples
new_dict = {}
for i in names_tuple:
    new_dict[i[1]] = sequence[i[0]]
new_dict

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.

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.

seq_names = zip(data['old_name'], data['new_name']) # brings together old and new names in tuples
renamed_sequence = {}
for i in seq_names:
    renamed_sequence[i[1]] = sequence[i[0]]
renamed_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.

added 4 characters in body
Source Link
haci
  • 4.2k
  • 1
  • 7
  • 28

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_tuple = zip(data['old_name'], data['new_name']) # brings together old and new names in tuples
new_dict = {}
for i in names_tuple:
    new_dict[i[1]] = sequence[i[0]]
new_dict

~~AndEDIT: 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.~~

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_tuple = zip(data['old_name'], data['new_name']) # brings together old and new names in tuples
new_dict = {}
for i in names_tuple:
    new_dict[i[1]] = sequence[i[0]]
new_dict

~~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.~~

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_tuple = zip(data['old_name'], data['new_name']) # brings together old and new names in tuples
new_dict = {}
for i in names_tuple:
    new_dict[i[1]] = sequence[i[0]]
new_dict

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.

added 4 characters in body
Source Link
haci
  • 4.2k
  • 1
  • 7
  • 28

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_tuple = zip(data['old_name'], data['new_name']) # brings together old and new names in tuples
new_dict = {}
for i in names_tuple:
    new_dict[i[1]] = sequence[i[0]]
new_dict

And~~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.~~

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_tuple = zip(data['old_name'], data['new_name']) # brings together old and new names in tuples
new_dict = {}
for i in names_tuple:
    new_dict[i[1]] = sequence[i[0]]
new_dict

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.

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_tuple = zip(data['old_name'], data['new_name']) # brings together old and new names in tuples
new_dict = {}
for i in names_tuple:
    new_dict[i[1]] = sequence[i[0]]
new_dict

~~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.~~

Source Link
haci
  • 4.2k
  • 1
  • 7
  • 28
Loading