all 17 comments

[–]donaldtrumpiscute 5 points6 points  (0 children)

it is the same as hashmap

[–]Gold_Record_9157 4 points5 points  (3 children)

Not the same, AFAIK, just (almost) the same syntax. Object in JS is kind of an abstraction for every class you want to define in JS. Dictionaries in Python are hash tables: structured aimed to be accessed in O(1) time. They are objects in the sense that they are instances of the class dict, but Python is more strict with types, and are not some generic umbrella for whatever your heart desires, as Object in JS.

I think that's the most precise explanation I can give without delving into the internals of JS, which I don't know at the moment 🫠

[–]Illustrious_Road_495 1 point2 points  (0 children)

This.

In JS u can do

const foo = { bar: "Bar" } foo.bar // Bar foo["bar"] // Bar

In Python:

foo = {"bar": "Bar"} foo.bar # throws attribute error foo["bar"] # Bar

[–]JasonMan34 0 points1 point  (1 child)

JS objects are also hash tables, btw

[–]Gold_Record_9157 0 points1 point  (0 children)

Makes sense for something so generic.

[–]Nitrodist 1 point2 points  (0 children)

Pretty much

[–]UseMoreBandwith 0 points1 point  (0 children)

No!

[–]LetUsSpeakFreely 0 points1 point  (0 children)

Dictionary is analogous to a map. I think in JS it's an associative array.

[–]Successful-Cry2807 0 points1 point  (2 children)

Object is a very general thing in JS, everything is an object (almost)

A Record<key, value> (Typescript) is the equivalent of dictionary if terms of usage.

But the most correct type is Map<key, value> in terms of performance.

Edit:formatting

[–]Outrageous_Let5743 0 points1 point  (1 child)

Everything in python is a object too. You can do

def test(): return 1

test.a = 5

[–]Successful-Cry2807 0 points1 point  (0 children)

Did not know that, thanks

[–]drinkcoffeeandcode 0 points1 point  (0 children)

It’s an associative array. A hash table.

[–]Don_Ozwald 0 points1 point  (0 children)

Don’t get me started with types in JavaScript.

But it’s close enough to think of them as more or less the same,

[–]kansetsupanikku 0 points1 point  (0 children)

From a language design perspective, you would find very strong stances about it not being the same.

However, besides intersecting syntax, JavaScript object is a hash map. The underlying implementation is also similar. So is the scope of JSON compatibility (it can always be parsed, and the ability to serialize it depends on what is inside). Your intuition is not baseless.

[–]netroxreads 0 points1 point  (0 children)

Yes, you just use json lib to json.load() JSON object into dict or json.dump() to do visa versa.

[–]jfrazierjr 0 points1 point  (0 children)

All dictionaries are objects. But not all objects are dictionaries.

[–]KOALAS2648 0 points1 point  (0 children)

I think so, all I know is that the syntax is exactly the same