Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32560 > unrolled thread

Re: Negative array indicies and slice()

Started byChris Angelico <rosuav@gmail.com>
First post2012-11-02 01:40 +1100
Last post2012-11-02 01:40 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Negative array indicies and slice() Chris Angelico <rosuav@gmail.com> - 2012-11-02 01:40 +1100

#32560 — Re: Negative array indicies and slice()

FromChris Angelico <rosuav@gmail.com>
Date2012-11-02 01:40 +1100
SubjectRe: Negative array indicies and slice()
Message-ID<mailman.3150.1351780831.27098.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web