当前位置:  首页>> 技术小册>> Python合辑4-130个字符串操作示例

找到两个字符串之间的差异位置

  1. def dif(a, b):
  2. return [i for i in range(len(a)) if a[i] != b[i]]
  3. print(dif('stackoverflow', 'stacklavaflow'))

Output:

  1. [5, 6, 7, 8]