Ask Your Question
0

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

asked 7 years ago

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..

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 7 years ago

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.

Preview: (hide)
link

Comments

Tank you very much

logomath gravatar imagelogomath ( 6 years ago )

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 7 years ago

Seen: 2,459 times

Last updated: Mar 30 '18