Find the position of difference between two strings

前端 未结 6 1571
别那么骄傲
别那么骄傲 2021-01-04 00:08

I have two strings of equal length, how can I find all the locations where the strings are different?

For example, \"HELPMEPLZ\" and \"HELPNEPLX\" are different at p

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-04 00:37

    >>> from itertools import izip
    >>> s1 = 'HELPMEPLZ'
    >>> s2 = 'HELPNEPLX'
    >>> [i for i,(a1,a2)  in enumerate(izip(s1,s2)) if a1!=a2]
    [4, 8]
    

提交回复
热议问题