lundi 6 février 2017

Is there any good reason for the python range function not to accept sequence arguments?

As the titel says, I'm wondering why the range builtin in its one argument form doesn't accept a sequence as its argument. I can only see positives, so I was wondering whether I am missing something obvious.

  • Considering how often I and I'm sure many others have typed range(somelist) when they meant range(len(somelist)) the meaning should be obvious
  • I fail to see any other ways it could be interpreted in
  • It would remove redundancy and one level of parenthesis nesting and save typing and line width in a location where linebreaks are especially harmful to readability
  • I couldn't see it breaking any code

So my question is (please refrain from merely venting opinions)

  • Are there any good (objective, Python Zen is acceptable) arguments against which I may have missed?
  • Is there perhaps already a convenience function for range(len(x))?

Optionally (if somebody happens to know)

  • Was this ever considered by the Python developers? What if any is the BDFL's position?
  • Why is there no arange_like or indices_like in numpy? (Or is there?)

Aucun commentaire:

Enregistrer un commentaire