avatar Bite 196. Create a JS-like dict object

In this Bite we challenge you to make a dict-like object that supports attribute lookups, just like JS objects!

Check out the docstring and tests for more info ... basically after creating an object, e.g. JsObject(a=1, b=2, c=3), we can access it by both key and attribute. So in this case both D['c'] and D.c would return 3. We also test for other dict operations / behaviors.

Disclaimer: take this as an exercise of inheritance and dict internals, but keep in mind that it violates Zen of Python's There should be one -- and preferably only one -- obvious way to do it, so probably not something you would use in your production code use!

Other than that, have fun and keep calm and code in Python!

Login and get coding
go back Advanced level
Bitecoin 4X

Will you be Pythonista #63 to crack this Bite?
Resolution time: ~53 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 5.71 on a 1-10 difficulty scale.
» Up for a challenge? 💪

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help