I am trying to learn python3 and tuple. It to be going nice smooth unless I tried to accessibility an element from a tuple of mine program. The throws earlier an error: typeerror: tuple indices must be integers or slices, no tuple
What's wrong? any kind of explanation?
askedMar 25, 2020Gavin15.3k points
In python list and tuple room just basic sequences. Wecan only accessibility their items by counting. Anyway,items stored in a dictionary are accessed v keys and not by counting together their items have no certain order. You have the right to use tuples as secrets of a dict, but an table of contents or a slice renders no sense for a dict, simply as a key makes no feeling for a list or a tuple.
You are watching: List indices must be integers or slices not tuple
answeredMar 25, 2020Naymulhasan94.3k points
Your comment on this answer:
|Your name to display (optional):|
|Email me in ~ this deal with if a comment is included after mine:Email me if a comment is included after mine|
Tuple finish list indices need to be ints or slices, due to the fact that tuples and also lists are just an easy sequences. You can only accessibility their items by counting. However, items stored in a thesaurus are accessed v keys and also not by counting together their items have actually no specific order.
When you shot to accessibility a member that a list or tuple, which i suppose picture is you perform it v an integer within sqare brackets favor so :
This would access the int(s) member of photo list/tuple. If this member wake up to it is in a list also, you can access it's memebers by adding another square bracket with an inte inside it point out the index of this member. If her loop is taking you through matrix of pixels in picture this provides sense additionally since with the an initial loop you could be going through rows of pixels and also with the second through columns and try to retreive the RGB values.
answeredMay 25, 2020Tushar Shuvro31.7k points
Your discuss this answer:
|Your surname to display screen (optional):|
|Email me in ~ this resolve if a comment is added after mine:Email me if a comment is added after mine|
Problem; assistance is needed because I have actually been unable to find a solution : Python perform indices need to be integers or slices, no tuple
askedJun 24nila180k points
Problem: So, I"m not entirely sure what"s going on here, but for everything reason Python is throwing this in ~ me. Because that reference, it"s component of a small neural network I"m building for fun, yet it supplies a most np.array and such, so there"s a most matrices ... Type clash. Perhaps somebody can aid me number this out, due to the fact that I"ve to be staring at this error for too lengthy without gift able to solve it.
See more: Stress Relief Gloves For Crocheting, Stress Relief Gloves, Do They Really Work
askedFeb 16Mashhoodch13k points
Problem: Hello! i am fully new to Python and also trying to grasp ideas in Python. While ns was discovering lists and also dictionaries, I wrote the adhering to program: surname = <"John", "Alice", "Catherine"> diction = "name" : "Alice" print(name) as soon as I ... ; together a value and also the program must print “Alice” top top screen. I execute not know what I have done wrong. Have the right to anybody help?
Problem: I have actually a regime where I used tuple and also it is cram e part eror message. The password I worte is : income random board = <> because that x in range(0,5): board.append(<"O"> * 5) def print_board(board): for row in board: publish " ".join(row) print_board(board) ... Len(board)-1 or guess_col len(board<0>)-1: TypeError: perform indices must be integers not tuple just how to deal with this thing?
Problem: I have actually been banging mine head versus this for two days now. I am new to python and programming for this reason the other examples of this form of error have actually not helped me to much. I am analysis through the documentation because that lists and also tuples, but haven"t uncovered anything ... Be lot appreciated. Not searching for the price necessarily, just much more resources on wherein to look. I am making use of Python 2.7.6. Thanks
Problem: I have actually been banging my head versus this for 2 days now. I am brand-new to python and also programming therefore the other examples of this kind of error have not helped me come much. I am reading through the documentation for lists and also tuples, however haven"t discovered anything ... Would be much appreciated. Not trying to find the answer necessarily, just more resources on whereby to look. Ns am utilizing Python 2.7.6.