why in returns values for array and keys for dictionary

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Tue Aug 26 00:30:47 EDT 2008


On Mon, 25 Aug 2008 19:57:06 -0700, alex23 wrote:

> On Aug 26, 10:49 am, "++imanshu" <himanshu.g... at gmail.com> wrote:
>>     Wouldn't it be nicer to have 'in' return values (or keys) for
>>     both
>> arrays and dictionaries. Arrays and Dictionaries looked so similar in
>> Python until I learned this difference.
> 
> […]
>
> In both cases, 'in' returns a boolean indicating the existence of an
> item in the list, or a key in the dict. I'm not sure why you'd need it
> to return the item you're checking for the existence of, as you'd have
> to have that item before you could do the check.
> 
> Have I missed what you're asking for here? Could you provide a
> pseudocode example to demonstrate what you mean?

The OP isn't talking about the ``in`` operator but ``in`` as part of 
``for … in …``.  So it's actually the question why ``list(a_dict)`` 
doesn't return a list of values but a list of keys.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list