s = ["this", "this", "and", "that"]
for i in xrange(1,len(s)):
if s[i] == s[i-1]:
print s[i]
Run Code Online (Sandbox Code Playgroud)
编辑:
正如旁注,如果你使用python 3.X使用range而不是xrange
strings = ['this', 'this', 'and', 'that']
for a, b in zip(strings, strings[1:]):
if a == b:
print a
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17318 次 |
| 最近记录: |