Arc Forumnew | comments | leaders | submitlogin
1 point by sjs 6170 days ago | link | parent

"aoeui"[3:1] ??? "aoeui"[12:42] ?? "aoeui"[0:0]

With or without negative indices one can do pointless things with slicing/subseq. Returning an empty string/list is the only sane thing to do in those cases.

    >>> s="aoeui"
    >>> s[3:1]
    ''
    >>> s[4:-3]
    ''
    >>> s[9:-20]
    ''
    >>> s[0:-0]
    ''
    >>> s[12:42]
    ''


1 point by mec 6170 days ago | link

Why not return the reverse when going backwards within bounds?

    >>> s="aoeui"
    >>> s[3:1]
    "eoa"
    >>> s[4:-3]
    "ue"
    >>> s[9:-20]
    ''
    >>> s[0:-0]
    'a'
    >>> s[12:42]
    ''

-----

2 points by sjs 6170 days ago | link

That is too magic for my taste. [0:-0] returning the first char is madness. That should be '' no matter what, as 0 == -0 on modern cpus (thankfully).

-----