[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] Question about .substring
From: |
Ralph Corderoy |
Subject: |
Re: [Groff] Question about .substring |
Date: |
Thu, 20 Nov 2014 14:37:19 +0000 |
Hi Tadziu,
> > second parameter that gives an empty string, unlike the
> > [startindex, endindex) interval where endindex is exclusive,
> > e.g. Python.
>
> But that's not to say that the python way is in any way
> more intuitive or useful. Example:
>
> >>> print [1,2,3,4,5,6,7,8][-1]
> --> 8
> >>> print [1,2,3,4,5,6,7,8][-2:-1]
> --> [7]
>
> which makes negative indices pretty useless for retrieving
> a subrange that includes the last element...
If the colon is given then either or both of the indices can be omitted.
>>> s = 'abcdefghij'
>>> s[3], s[:3], s[3:], s[-3:], s[:]
('d', 'abc', 'defghij', 'hij', 'abcdefghij')
The other nice thing about [) is that you can shuffle the indexes along
and cover the whole array, i.e. the end index last time becomes the
start index this time.
>>> s = 'abcdefghij'
>>> s[0:3], s[3:6], s[6:9], s[9:12]
('abc', 'def', 'ghi', 'j')
[) has become the norm in "new" languages?
https://en.wikipedia.org/wiki/Interval_%28mathematics%29#Notations_for_intervals
Cheers, Ralph.
- Re: [Groff] Question about .substring, (continued)
- Re: [Groff] Question about .substring, Tadziu Hoffmann, 2014/11/19
- Re: [Groff] Question about .substring, Steffen Nurpmeso, 2014/11/19
- Re: [Groff] Question about .substring, Ingo Schwarze, 2014/11/19
- Re: [Groff] Question about .substring, Steffen Nurpmeso, 2014/11/19
- Re: [Groff] Question about .substring, Ingo Schwarze, 2014/11/19
- Re: [Groff] Question about .substring, Ralph Corderoy, 2014/11/19
- Re: [Groff] Question about .substring, Steffen Nurpmeso, 2014/11/20
- Re: [Groff] Question about .substring, Ingo Schwarze, 2014/11/20
- Re: [Groff] Question about .substring, Ralph Corderoy, 2014/11/20
- Re: [Groff] Question about .substring, Tadziu Hoffmann, 2014/11/20
- Re: [Groff] Question about .substring,
Ralph Corderoy <=
- Re: [Groff] Question about .substring, Tadziu Hoffmann, 2014/11/20
- Re: [Groff] Question about .substring, Steffen Nurpmeso, 2014/11/28
- Re: [Groff] Question about .substring, Ralph Corderoy, 2014/11/29
- Re: [Groff] Question about .substring, Steffen Nurpmeso, 2014/11/22
- Re: [Groff] Question about .substring, Carsten Kunze, 2014/11/20
- [Groff] .fl (was: Question about .substring), Carsten Kunze, 2014/11/20
- Re: [Groff] Question about .substring, Ralph Corderoy, 2014/11/19
- Re: [Groff] Question about .substring, Ulrich Lauther, 2014/11/19
- Re: [Groff] Question about .substring, Ralph Corderoy, 2014/11/20