Ask Your Question
1

How to check the existence of an element in an array ?

asked 2013-04-30 09:22:09 -0500

Mongo gravatar image

Hi friends,

Please, suppose that I have:

fr = [ 2,5,6]

Now I wanna check if a 4th element exists in the array, and the result would be NO, please is there a way to check it ?

Please note that I wanna check if an element exists in a certain position, not the element itself;

Thanks,

Andre

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-05-01 00:14:03 -0500

Eli Pack gravatar image

To check if a 4th element exists, you just need to determine the size of the list. The following line will check to see if a 4th element exists:

len(fr) >= 4

Note that even if you delete an item from the middle of your list, the indexes of the items after it will be shifted so that there are no gaps in your list.

edit flag offensive delete link more

Your Answer

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

Add Answer

[hide preview]

Question Tools

Stats

Asked: 2013-04-30 09:22:09 -0500

Seen: 240 times

Last updated: May 01 '13