Ask Your Question

Is there a command to find the place of an element in an array?

asked 2018-03-30 11:39:59 +0200

logomath gravatar image

For example, let v=[a, b, c, d] I wonder if there is already encoded a function f such that f(a)=0, f(b)=1, f(c)=2..

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-03-30 16:35:00 +0200

B r u n o gravatar image

You can use v.index(a) to get the index of the first occurrence of a. An exception is raised if a is not in v.

edit flag offensive delete link more


Tank you very much

logomath gravatar imagelogomath ( 2018-04-10 06:31:38 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2018-03-30 11:39:59 +0200

Seen: 1,812 times

Last updated: Mar 30 '18