+ 1

JavaScript and Python Queries

Are Python Dictionaries the same as JavaScript Objects? Also, can Python dictionaries be used as values in higher-level Python dictionaries like JavaScript objects can be nested? Thanks in advance

21st Aug 2020, 3:46 AM
Devansh Patil [INACTIVE]
Devansh Patil [INACTIVE] - avatar
2 odpowiedzi
+ 3
Yes, Python's dictionaries are very similar to JavaScript's objects in that a JavaScript object can be used as a container for many key-value pairs. Recent versions of JavaScript also have a Map( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map ) type that is more like Python's dictionary than JavaScript's objects because a Map is more specialized. JavaScript's objects can be used for representing much more than key-value pairs which is unlike Python's dictionary. JavaScript Arrays are objects despite arrays being more like Python's list type. Yes, JavaScript objects, Python's dictionaries, and JavaScript Map can all be used to represent very deep trees or even cyclic graphs of deeply nested data.
21st Aug 2020, 3:36 PM
Josh Greig
Josh Greig - avatar
+ 2
Python dictionnaires and JS objects aren't the same at all, even if dictionaries have a big importance in Python data model (dictionaries are used to store all variables / functions you create, and all objects but the ones defining __slots__ have a __dict__ attribute storing all the object attributes (not the methods, since the must be part of the class, not of an instance) ). But dictionaries still remains a data type in Python (type 'dict'). Dictionnaires in Python are only hash maps, nothing else. Dictionnaires can be nested in Python.
21st Aug 2020, 3:37 PM
Théophile
Théophile - avatar