Skip to content

Instantly share code, notes, and snippets.

View jakubblaha-ids's full-sized avatar

jakubblaha-ids

View GitHub Profile
@dschep
dschep / py-comp-to-js.md
Last active May 21, 2024 12:58
Python Comprehensions to JS

Python list & dict comprehensions translated to JavasScript

Comprehensions are a really useful feature of Python that aren't available in JavaScript (or many languages). These concepts of course can be tranlsated into using map instead. But especially the dictionaries are a bit trickier.

Lists / Arrays

>>> foobar = range(5)
>>> [x + 1 for x in foobar]
[1, 2, 3, 4, 5]