In Python, how to check whether a key already exists in a dict?

How to check whether a key already exists in a dict in Python since version 2.6?

asked Oct 3, 2016 by anonymous

1 Answer

If d is a dict(), you can directly test whether a key k is in d in Python by the in keyword like

if k in d:
  ..
answered Oct 8, 2016 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...