This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-29
Channels
- # babashka (30)
- # beginners (207)
- # biff (3)
- # calva (10)
- # cljs-dev (3)
- # clojure (34)
- # clojure-austin (3)
- # clojure-bay-area (1)
- # clojure-dev (3)
- # clojure-europe (31)
- # clojure-nl (1)
- # clojure-norway (37)
- # clojure-uk (8)
- # community-development (3)
- # core-async (4)
- # data-science (1)
- # dev-tooling (2)
- # emacs (4)
- # etaoin (12)
- # fulcro (7)
- # gratitude (1)
- # hyperfiddle (7)
- # jobs-discuss (191)
- # lsp (15)
- # malli (1)
- # other-languages (11)
- # overtone (1)
- # pathom (3)
- # pedestal (1)
- # polylith (21)
- # releases (1)
- # squint (5)
- # yamlscript (5)
This is one-level flatten in Python:
def flatten(lst):
return [e for es in lst for e in es]
First part, e for es in lst
is simple - but then it seems the last part for e in es
... hm ... somhow operates on the same es
? But that e
is a different e
?
these are written in a DSL that's like nested loops but without the indentation
return [e for es in lst for e in es]
can be read like this:
ret = []
for es in lst:
for e in es:
ret.append(e)
return ret
👍 1
that is to say the [e for ...]
is like saying append to a new list each of e
. and then for es in lst
and for e in es
are two for loops but flattened into the list comprehension
for es in lst, for e in es, return a sequence of e
Ah, yes so it's read as
python'ish
for es in lst
for e in es
e
so
clojure
(for [es lst
e es]
e)
👍 1
Thanks @UEENNMX0T!
glad to help