我的代码应该打印一个包含输入字母 ( s)的字典,并为每个字符分配一个特定长度( 的长度s)内的随机数。当它尝试添加一个已经在字符串中的字母时,它会跳过它,但它不应该这样做。
我的代码:
import random as r
def strhash(s):
x = 0
y = 0
z = 0
ind = {
}
ra = 0
while z != len(s):
ra = r.randint(0, len(s))
x += 1
y = x-1
ind[s[y:x]] = ra
z += 1
return ind
print(strhash('hello'))
Run Code Online (Sandbox Code Playgroud) python ×1