News for hackers. Stuff that matters.
Re:PEP 572: Python assignment expressions has been accepted by joeframbach on Tuesday July 03, 2018 @12:29PM (#17451517)
[found_node.get("value") for node in tree if (found_node := node.find(SOME_XPATH)) is not None]

tree.map(node => node.find(SOME_XPATH)).filter(Boolean).map(node => node.get("value"))

I can deal with either language at this level of complexity. Anything more complicated needs more LoC in either language.

Re:PEP 572: Python assignment expressions has been accepted by williamdclt on Tuesday July 03, 2018 @04:20PM (#17453332)
I vastly prefer the second one, as I would expect to see it written something like this:

  tree
    .map(node => node.find(SOME_XPATH))
    .filter(Boolean)
    .map(node => node.get("value"))
I don't use Python on a daily basis, but I find that infinitely more readable than the comprehension version (plus, it's a syntax used in several major languages)
Re:PEP 572: Python assignment expressions has been accepted by lukeschlather on Tuesday July 03, 2018 @05:40PM (#17453797)
In fairness, the Python also should be broken up. It should be:

    [
      found_node.get("value") 
      for node in tree 
      if (found_node := node.find(SOME_XPATH)) is not None
    ]
I think I also prefer Ruby/Javascript style comprehensions, but it's worth comparing well formatted code.
Re:PEP 572: Python assignment expressions has been accepted by hellofunk on Tuesday July 03, 2018 @04:32PM (#17453415)
What is "node => ", is that valid Python? I'm new to the language and have never seen the => syntax before. The docs for 'map' don't show it either.
Re:PEP 572: Python assignment expressions has been accepted by vthriller on Tuesday July 03, 2018 @05:10PM (#17453649)
It's not Python, the second is actually a counterexample in JavaScript, where `node =>` is similar to Python's `lambda node:`