this post was submitted on 29 Aug 2023
33 points (100.0% liked)

Python

6393 readers
14 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

๐Ÿ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

๐Ÿ Python project:
๐Ÿ’“ Python Community:
โœจ Python Ecosystem:
๐ŸŒŒ Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 4 points 1 year ago* (last edited 1 year ago)

not unique to python.

function pointers and hashmaps exist in basically all languages

like in lua:

local table = {
  add = function(a, b) return a + b end
}
table["add"](4, 5)

JavaScript:

{
  add: (a, b) => a + b
}

Rust (using hashmaps with string keys is extremely inefficient tho, there are much better options here but whatever)

let map = HashMap::from([
   ("add", |a, b| a + b),
]);

//...

map["add"](1, 3);