←back to thread

317 points est | 1 comments | | HN request time: 0.269s | source
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 #
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 #
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 #
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 #
zb ◴[] No.17451148[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 #
msluyter ◴[] No.17453601[source]
Sure; it wasn't clear to me whether the letter fields could be repeated.
replies(1): >>17459132 #
1. mehrdadn ◴[] No.17459132[source]
Why would I have included the indices for sorting if the letters were guaranteed to be distinct...