Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32560
| References | (1 earlier) <CALwzidnQ2bUdMp8c0xNomabcLHZBBtr_DYSSzvhz3jqeYNkWkQ@mail.gmail.com> <50912ADC.2020401@r3dsolutions.com> <CALwzid=_1TCQC5JryemVfVpBLWq=qZwy4hRjCPA5ha0vSm3=VA@mail.gmail.com> <50918716.3080305@r3dsolutions.com> <5092833F.4070609@stoneleaf.us> |
|---|---|
| Date | 2012-11-02 01:40 +1100 |
| Subject | Re: Negative array indicies and slice() |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3150.1351780831.27098.python-list@python.org> (permalink) |
On Fri, Nov 2, 2012 at 1:12 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
> In other words, the slice contains the strings, and my code calculates
> the offsets -- Python doesn't do it for me.
That's correct, but you're still translating those strings into
numeric indices. You can slice a database record based on column names
(though personally I would recommend against it - creates too much
dependence on column order, which I prefer to treat as
non-significant), but you can't, for instance, slice a dictionary by
keys:
foo = {"asdf":123,"qwer":234,"zxcv":345,"1234":456}
foo["qwer":"1234"] # What should this return?
I suppose conceptually you could slice any iterable by discarding till
you match the start, then yielding till you match the stop, then
returning (it'd function like itertools.islice but using non-numeric
indices - somehow). But it still depends on there being a dependable
order.
(Incidentally, isinstance(X, (str, unicode)) can become isinstance(X,
basestring) - they both inherit from that.)
ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Negative array indicies and slice() Chris Angelico <rosuav@gmail.com> - 2012-11-02 01:40 +1100
csiph-web