Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

With a good mix of comprehensions, itertools, functools and lambda, there is enough stuff to get creative with FP in Python anyway.


btw, my favorite FP-hack: let-in expressions with lambdas OR list comprehensions:

  let x = foo in expr
can be

  [expr for x in (foo,)][0]
(kinda reads like a Haskell `where` clause!) or:

  (lambda x = foo: expr)()
useful in a pre-walrus-operator REPL :)


If you want to program in Haskell, why don’t you get a job programming in Haskell rather than inventing something so ugly?

You would not get through code review with that in any shop that has discipline.


> You would not get through code review with that in any shop that has discipline.

... and i'd never think to try! that's why i mentioned using it in a REPL and called it a hack :) it's just fun. i played around with bytecode-rewriting too, doesn't mean i'd use it in production.

PS. for a less extreme version, the 1-elem-tuple trick is useful if you need an intermediate variable in a listcomp:

  [
    y+y
    for x in my_list
    for y in (foo(x),)
  ]
but it's (obviously) ugly & only useful if you're in a REPL and don't want to rewrite the whole thing.


Yeah but constantly jumping between idioms means this is stuff I have to usually look up instead of just intuiting.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: