Test for element in array
Ivan Senji
ivan.senji_REMOVE_ at _THIS__gmail.com
Fri Jul 14 01:33:09 PDT 2006
BCS wrote:
> Andrei Khropov wrote:
>> Paolo Invernizzi wrote:
>>
>>
>>> Hi all,
>>>
>>> Someone can suggest me the best way for testing the presence of an
>>> element in
>>> an array?
>>>
>>> Coming from python, something like...
>>>
>>> if( x in array_of_x && y in array_of_y ){
>>> ...
>>> }
>>>
>>> The workaround, apart from using a simple 'for' loop, is to use an
>>> associative array, and test for key...
>>>
>>> ---
>>> Paolo
>>
>>
>> Despite BCS proposed a cool solution
>
> thanks
>
>> I think 'in' should be built-in for usual (non-associative) arrays
>> too. why not?
>>
>>
>
> the semantics are backwards, not a killer but its a little inconsistent.
Yeah, some think it is some think it isn't, I think it isn't but it is
an old discussion and probably one we will never agree on.
IMO:
normal arrays store *values* which are indexed by a key (index)
associative arrays store *keys* and the value is just an additional
information about the key.
That is only my opinion as some people think that AA's also are about
values.
More information about the Digitalmars-d-learn
mailing list