Most active commenters
  • mehrdadn(3)

←back to thread

317 points est | 14 comments | | HN request time: 1.853s | source | bottom
Show context
roel_v ◴[] No.17448647[source]
Having just spend the last few weeks writing Python, this comment will come off as bitter, but - really? Out of all the shitty syntax things, this sort of thing is what they're willing to fix?
replies(7): >>17448692 #>>17448695 #>>17448702 #>>17448723 #>>17448807 #>>17448862 #>>17448928 #
1. vanderZwan ◴[] No.17448695[source]
It would be more constructive if you added explanations of what other (in your opinion) "shitty syntax" things you prefer to see addressed and why.

EDIT: also, I'm mentioning "in your opinion" because adding that to your own statements indicates that you're open to discussion. It's also good to use it as a reminder to yourself (speaking as a former physics student, and most people who know physics students will agree how "absolute" and unintentionally arrogant they tend to be in their claims until they learn otherwise).

I'm sure your coding experience was frustrating, and I'm sorry to hear that, and I understand that we all need to vent sometimes, but trying to staying open to other viewpoints is better for your own sanity, wisdom, and social connections in the long run.

replies(1): >>17448734 #
2. mehrdadn ◴[] No.17448734[source]
Not the OP, but the inability to write

  sorted(enumerate([('a', 1), ('b', 2)]), key=lambda (i, (k, v)): (k, i, v))
in Python 3 drives me nuts. They could fix this. It worked in Python 2.
replies(3): >>17448753 #>>17448887 #>>17448994 #
3. fredley ◴[] No.17448753[source]
I love writing python, but the lack of decent map/reduce/etc. (that are really good in Javascript - the other language I mainly write) hurts. Stuff like your example really feels burdensome and inelegant in comparison.
replies(1): >>17448900 #
4. icebraining ◴[] No.17448887[source]
Yeah, PEP 3113 was quite weak. It didn't even explore alternatives (like fixing the introspection without breaking the syntax).
5. pxndx ◴[] No.17448900{3}[source]
Python list comprehensions _are_ map/reduce.
replies(2): >>17448907 #>>17449257 #
6. mehrdadn ◴[] No.17448907{4}[source]
I think you mean map/filter.
replies(1): >>17453786 #
7. msluyter ◴[] No.17448994[source]
Seems that the goal here is to sort via the letters 'a', 'b', etc combined with capturing the original ordering?

You could do this, although it's admittedly uglier than your example:

  In [1]: sorted(enumerate([('b', 1), ('c', 3), ('a', 2)]), key=lambda x: (x[1][0], x[0], x[1][1]))
  Out[1]: [(2, ('a', 2)), (0, ('b', 1)), (1, ('c', 3))]
However, if you're flexible about the ordering of the resulting tuples, this seems clearer and reasonably painless:

  In [1]: sorted((x, i) for i, x in enumerate([('b', 1), ('c', 3), ('a', 2)]))
  Out[1]: [(('a', 2), 2), (('b', 1), 0), (('c', 3), 1)]
I know that doesn't address your underlying complaint. This is mainly to note that the flexibility of Python tends allow a variety of approaches and that sometimes finding the clearest one takes some effort. ("There should be one obvious way to do it..." often does not hold, IMHO.)
replies(1): >>17451148 #
8. yxhuvud ◴[] No.17449257{4}[source]
Sure, but they compose really bad.
replies(1): >>17453279 #
9. zb ◴[] No.17451148{3}[source]
> this seems clearer and reasonably painless

but gives the wrong answer, as you'll see if you try to sort [('a', 2), ('a', 1)]

replies(1): >>17453601 #
10. vanderZwan ◴[] No.17453279{5}[source]
Why? Just assign to a variable, then do another list comprehension on the next line, no?
replies(1): >>17469471 #
11. msluyter ◴[] No.17453601{4}[source]
Sure; it wasn't clear to me whether the letter fields could be repeated.
replies(1): >>17459132 #
12. pxndx ◴[] No.17453786{5}[source]
Yes, thanks for correcting me.
13. mehrdadn ◴[] No.17459132{5}[source]
Why would I have included the indices for sorting if the letters were guaranteed to be distinct...
14. yxhuvud ◴[] No.17469471{6}[source]
And that is a pretty sad state of affairs compared to ways that do compose well, like the one in Ruby which you can easily chain.