Python multiple items get indices

How to get the indices from a list compared with multiple items.
I now get the error:

Runtime error (ValueErrorException): list.index(item): item not in list
  line 18, in script

00 python multiple items get (5.5 KB)


The list.index command compares it’s argument to every element in the list. So, what you are checking is whether the whole pt_neighbors list is included as an entry in the base list.

You should rather use a for loop, and check each item in the pt_neighbors list individually with list.item.

Also, list.index returns an error if the element is not in the list, so you might want to check if the element is in the list before calling list.index.

1 Like

Thank you Rossi for your response.

You explanation makes me curious about what list.index() actually is, do you know, works list.index() also like a kind of loop?

Hi Edward, you should really go through the Python basics and keep the Python docs handy. In this case:

Thank you for mentioning. I previously went through.

However, I want to understand it deeper, so it becomes even more understand by myself than what is understand by me of what is written.

That’s why you wanna keep the docs handy, so that you can look up e.g. list.index() on the fly (instead of having to ask).

Yes, I understand that.
However, these documents does not explain ‘why’ it is created.

That is what I was interested in.

Unless you’re talking about a more general (i.e. computer scientific) “why”, I’m failing to see how this doesn’t answer what list.index() does.

I do not understand what point you want to make connected to my question.
I like your replies from previous posts, thank you for those.

I did not intend to act on any different ‘intention.’
Again, thank you for your previous replies/posts.

Do you might know why I get only one False with this used method (enumerate), I should get at least nine of them?


Never mind, I got it.