Python - difference between two strings

前端 未结 5 1653
余生分开走
余生分开走 2020-11-27 13:41

I\'d like to store a lot of words in a list. Many of these words are very similar. For example I have word afrykanerskojęzyczny and many of words like afr

5条回答
  •  北海茫月
    2020-11-27 14:28

    I like the ndiff answer, but if you want to spit it all into a list of only the changes, you could do something like:

    import difflib
    
    case_a = 'afrykbnerskojęzyczny'
    case_b = 'afrykanerskojęzycznym'
    
    output_list = [li for li in difflib.ndiff(case_a, case_b) if li[0] != ' ']
    

提交回复
热议问题