TypeError: list indices must be integers or slices, not range - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: TypeError: list indices must be integers or slices, not range (/thread-37004.html) |
TypeError: list indices must be integers or slices, not range - Anldra12 - Apr-22-2022 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
RE: TypeError: list indices must be integers or slices, not range - Gribouillis - Apr-22-2022 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] ?
RE: TypeError: list indices must be integers or slices, not range - Anldra12 - Apr-22-2022 @Gribouillis Thanks you yeah I find the mistake to change it F(:-1): |