我遇到了一个令人费解的挑战.我必须多次检查一个数字是否包含相同的数字.11,424,66等.起初这似乎很容易,但我很难找到一个逻辑来检查这一点.有任何想法吗?
这是我到目前为止所得到的.该函数接受一个列表.(更新)
arr = [[1,20],[1,10]]
for i in arr:
l = list(range(i[0],i[1]))
for num in l:
if num < 11: continue
for c in str(num):
if str(num).count(c) > 1:
# dont know why code is popping off 12 and 13
print(l.pop(num))
Run Code Online (Sandbox Code Playgroud)
如果你的最终目标只是检测是否有双,这个功能可能会有所帮助:
def has_doubles(n):
return len(set(str(n))) < len(str(n))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4535 次 |
| 最近记录: |