Hi Arindam,
Another nice post. I thought you might be interested to know you don't need keys() to check if a key is in a dict. This is more idiomatic.
user = {'name': 'Raghav', 'age': 20, 'country': 'India'} 'name' in user True 'gender' in user False
Similarly, we often use sets to deduplicate list and provide fast lookups because a set is stored as a hash of values.
names = ['Bob', 'Dave', 'Stacey', 'Bob', 'Mags', 'Stacey'] set(names) {'Bob', 'Dave', 'Stacey', 'Mags'} 'Mags' in names True 'Mags' in set(names) True
The in keyword works on any iterable value... but I'm sure you will come to that soon enough. Enjoy your loops session. It's really cool stuff.
Cheers
Adrian
Thanks Adrian for the suggestion. My intent was to demonstrate that keys() method is the default one. I forgot to mention explicitly.
I am so glad you found it worth a read :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Arindam,
Another nice post. I thought you might be interested to know you don't need keys() to check if a key is in a dict. This is more idiomatic.
Similarly, we often use sets to deduplicate list and provide fast lookups because a set is stored as a hash of values.
The in keyword works on any iterable value... but I'm sure you will come to that soon enough. Enjoy your loops session. It's really cool stuff.
Cheers
Adrian
Thanks Adrian for the suggestion.
My intent was to demonstrate that keys() method is the default one. I forgot to mention explicitly.
I am so glad you found it worth a read :)