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

Missed python's slicing:

  >>> 'abcdefghijklmnopqrstuvwxyz'[1:20:4]
  'bfjnr'
It's start/end/skip, with default values of 0, length, 1; each can be omitted so it's rare to see the third one unless someone is showing off how to reverse a string:

  >>> 'abcdefghijklmnopqrstuvwxyz'[::-1]
  'zyxwvutsrqponmlkjihgfedcba'
Though really these are slice objects, it's just the syntax only works inside array access:

  >>> slice
  <class 'slice'>
  >>> z = slice(1, 20, 4)
  >>> 'abcdefghijklmnopqrstuvwxyz'[z]
  'bfjnr'


I think this may fall (conceptually) under the range operators.




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

Search: