Python Forum
TypeError: list indices must be integers or slices, not range
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: list indices must be integers or slices, not range
#1
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
Reply
#2
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]?
Reply
#3
@Gribouillis Thanks you yeah I find the mistake to change it F(:-1):
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tuple indices must be integers or slices, not str cybertooth 16 11,081 Nov-02-2023, 01:20 PM
Last Post: brewer32
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,091 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  boto3 - Error - TypeError: string indices must be integers kpatil 7 1,184 Jun-09-2023, 06:56 PM
Last Post: kpatil
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,258 May-22-2023, 10:39 PM
Last Post: ICanIBB
Thumbs Down I hate "List index out of range" Melen 20 3,161 May-14-2023, 06:43 AM
Last Post: deanhystad
  Response.json list indices must be integers or slices, not str [SOLVED] AlphaInc 4 6,191 Mar-24-2023, 08:34 AM
Last Post: fullytotal
Question How to append integers from file to list? Milan 8 1,364 Mar-11-2023, 10:59 PM
Last Post: DeaD_EyE
  "TypeError: string indices must be integers, not 'str'" while not using any indices bul1t 2 1,931 Feb-11-2023, 07:03 PM
Last Post: deanhystad
  Error "list indices must be integers or slices, not str" dee 2 1,394 Dec-30-2022, 05:38 PM
Last Post: dee
  TypeError: string indices must be integers JonWayn 12 3,262 Aug-31-2022, 03:29 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020