You can do the same check using a default argument in dict.get such as...<div><br></div><div><div>>>> tel.get('jack', None) == 4098</div><div>True</div><div>>>> tel.get('jack', None) == 4000</div>
<div>False</div><div>>>> tel.get('jill', None) == 4000</div><div>False</div><div><br></div><br>- John<br><br><br><br>On Sun, Oct 9, 2011 at 4:25 PM, Karthick Sankarachary <<a href="mailto:karthick.sankarachary@gmail.com">karthick.sankarachary@gmail.com</a>> wrote:<br>
> Hello Python Ideas,<br>><br>> Currently, to check whether a single key is in a dictionary, we use the "in"<br>> keyword. However, there is no built-in support for checking if a key-value<br>> pair belongs in a dictionary.<br>
><br>> Currently, we presuppose that the object being checked has the same type as<br>> that of the key. What if we allowed the "in" operator to accept a tuple that<br>> denotes a (mapped) key-value pair?<br>
><br>> Let us consider how that might work using the canonical example given in the<br>> tutorial:<br>><br>>>>> tel = {'jack': 4098, 'sape': 4139}<br>><br>><br>>>>> ('jack', 4098) in tel<br>
> True<br>>>>> ('jack', 4000) in tel<br>> False<br>>>>> 'jack' in tel<br>> True<br>><br>> As you can see, the "in" operator would interpret the object as either a key<br>
> or a key-value pair depending on the actual types of the object, key and<br>> value. In the key itself happens to be a tuple, then the key-value<br>> membership test would involve a nested tuple, whose first item is a tuple<br>
> denoting the key.<br>><br>> Best Regards,<br>> Karthick Sankarachary<br>><br>> _______________________________________________<br>> Python-ideas mailing list<br>> <a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
> <a href="http://mail.python.org/mailman/listinfo/python-ideas">http://mail.python.org/mailman/listinfo/python-ideas</a><br>><br>><br><br></div>