S
Saketh
Hi everyone:
I'm using "translation" in the sense of string.maketrans here.
I am trying to efficiently compare if two string translations
"conflict" -- that is, either they differently translate the same
letter, or they translate two different letters to the same one. Here
are some examples:
# no conflict - equal
t1 = Translation('ab', 'cd')
t2 = Translation('ab', 'cd')
# no conflict - inverses
t1 = Translation('ab', 'cd')
t2 = Translation('cd', 'ab')
# conflict - same key, different value
t1 = Translation('ab', 'cd')
t2 = Translation('ab', 'ce')
# conflict - different key, same value
t1 = Translation('ab', 'cd')
t2 = Translation('xy', 'cd')
This conflict-checking is the bottleneck of my program, and the
obvious way to implement it -- looping through the translations and
explicitly checking for the above conditions -- is much slower than
I'd like.
Is there a more efficient, Pythonic way of checking if two
translations conflict?
Sincerely,
Saketh
I'm using "translation" in the sense of string.maketrans here.
I am trying to efficiently compare if two string translations
"conflict" -- that is, either they differently translate the same
letter, or they translate two different letters to the same one. Here
are some examples:
# no conflict - equal
t1 = Translation('ab', 'cd')
t2 = Translation('ab', 'cd')
# no conflict - inverses
t1 = Translation('ab', 'cd')
t2 = Translation('cd', 'ab')
# conflict - same key, different value
t1 = Translation('ab', 'cd')
t2 = Translation('ab', 'ce')
# conflict - different key, same value
t1 = Translation('ab', 'cd')
t2 = Translation('xy', 'cd')
This conflict-checking is the bottleneck of my program, and the
obvious way to implement it -- looping through the translations and
explicitly checking for the above conditions -- is much slower than
I'd like.
Is there a more efficient, Pythonic way of checking if two
translations conflict?
Sincerely,
Saketh