More random python observations from a perl programmer

Jeff Blaine jblaine at shell2.shore.net
Thu Aug 19 11:29:37 EDT 1999


>GOTCHA: (low)
>    You can't use "in" on dicts.  Instead, you must use 
>	d = { "fred":"wilma", "barney":"betty" }
>	if d.has_key("fred"):	# legal
>	if "fred" in d:	        # ILLEGAL
>    I don't understand why this was done.

I'm very curious what would you think should be legal.

Would 'in' (when used on a dict) search the keys, values, or both?

Each one of those seem like a bad idea to me.  You have 2 separate
areas containing data.  Searching each of those individually 
(has_key()...) seems right to me.

Thanks for the document.  It was very interesting reading.




More information about the Python-list mailing list