How to compare 2 text and replace the differences with python?

Viewed 26

So I want to compare 2 hex lines and find the differences. But I want it not only to show the differences, but its just replace all the differences.

I wanna to turn this :

E2 34 3D A6 00 C2 00 95
79 34 C0 AB 00 C2 00 95

Into this :
?? 34 ?? ?? 00 C2 00 95
1 Answers

You can something like this,

l1 = "E2 34 3D A6 00 C2 00 95" 
l2 = "79 34 C0 AB 00 C2 00 95"
    
" ".join(i if i==j else '??' for i,j in zip(l1.split(), l2.split()))
# '?? 34 ?? ?? 00 C2 00 95'
Related