Advertisement
here2share

# difflib_ndiff.py

Feb 3rd, 2022
759
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. # difflib_ndiff.py
  2.  
  3. import difflib
  4.  
  5. case=[("IsN't Pyth0n GrEaT?", 'Python Is Great!')]
  6.  
  7. for a,b in case:     
  8.     print('{} >>> {}'.format(a,b))
  9.     aaa = list(a)
  10.     bbb = list(b)
  11.     print(''.join(aaa))
  12.     for i,s in enumerate(difflib.ndiff(a, b)):
  13.         if s[0]==' ': continue
  14.         elif s[0]=='-':
  15.             aaa[i] = ''
  16.         elif s[0]=='+':
  17.             aaa.insert(i, s[-1])   
  18.         print(''.join(aaa))
  19.     print('')      
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement