Python Forum

Full Version: TypeError: list indices must be integers or slices, not range
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Get the TypeError: list indices must be integers or slices, not range

def getDistinctX(x_subi, F):
    x_subi = []
    ind = random.randint(1, 5)
    ind = range(0, (len(F)-1))
    x = F[ind]
    if not x in x_subi:
        return x
    else:
        x = getDistinctX(x_subi, F)
        return x
Error:
Traceback (most recent call last): File "/home/ali/Downloads/Attribute-Based-Encryption-master/LSSS_t,n.py", line 271, in <module> runPackage([], []) File "/home/ali/Downloads/Attribute-Based-Encryption-master/LSSS_t,n.py", line 255, in runPackage predefinedVars, returnK = initiateScheme(predefinedVars) File "/home/ali/Downloads/Attribute-Based-Encryption-master/LSSS_t,n.py", line 56, in initiateScheme recovered_k = runScheme(t, n, secret_k, q, Field) File "/home/ali/Downloads/Attribute-Based-Encryption-master/LSSS_t,n.py", line 101, in runScheme x = getDistinctX(x_subi, Field) File "/home/ali/Downloads/Attribute-Based-Encryption-master/LSSS_t,n.py", line 181, in getDistinctX x = F[ind] TypeError: list indices must be integers or slices, not range Process finished with exit code 1
It looks clear, if F is a list and ind is a range object, F[ind] is not a valid operation. It would be valid if ind was an integer or a slice object. Perhaps you meant F[:-1] instead of F[ind]?
@Gribouillis Thanks you yeah I find the mistake to change it F(:-1):