Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list.index() help
#4
Index only works on 1D lists because that is all there is in Python, You can make something that looks like a 2D list but it is really just a list of lists. That is why our index() call failed. Your list "sampleArray" only contains lists. None of these lists is '2020-07-25' or 9679, so index() correctly raises a ValueError.

bowlofred's numpy example works because numpy understands lists that contain lists that contain lists and knows how to do a deep search.
Reply


Messages In This Thread
list.index() help - by qmfoam - Aug-06-2020, 07:53 PM
RE: list.index() help - by buran - Aug-06-2020, 08:05 PM
RE: list.index() help - by bowlofred - Aug-06-2020, 08:14 PM
RE: list.index() help - by deanhystad - Aug-06-2020, 10:02 PM
RE: list.index() help - by qmfoam - Aug-07-2020, 07:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Down I hate "List index out of range" Melen 20 3,448 May-14-2023, 06:43 AM
Last Post: deanhystad
  IndexError: list index out of range dolac 4 1,969 Jul-25-2022, 03:42 PM
Last Post: deanhystad
  IndexError: list index out of range Anldra12 2 1,476 May-03-2022, 01:39 PM
Last Post: Anldra12
  IndexError: list index out of range rf_kartal 6 2,900 Sep-07-2021, 02:36 PM
Last Post: Larz60+
  Python Error List Index Out of Range abhi1vaishnav 3 2,363 Sep-03-2021, 08:40 PM
Last Post: abhi1vaishnav
  IndexError: list index out of range Laplace12 1 2,253 Jun-22-2021, 10:47 AM
Last Post: Yoriz
  IndexError: list index out of range brunolelli 11 6,673 Mar-25-2021, 11:36 PM
Last Post: brunolelli
  Changing Index of 2 List in python giddyhead 0 1,700 Mar-05-2021, 05:45 PM
Last Post: giddyhead
  IndexError: list index out of range ramu4651 2 3,784 Jan-24-2021, 01:45 PM
Last Post: buran
Question Matching variable to a list index Gilush 17 5,986 Nov-30-2020, 01:06 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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