Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32560
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'column': 0.07; 'indices': 0.07; 'suppose': 0.07; 'python': 0.09; 'calculates': 0.09; 'correct,': 0.09; 'subject:()': 0.09; '(str,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterable': 0.16; 'keys:': 0.16; 'offsets': 0.16; 'skip:{ 40': 0.16; 'subject:array': 0.16; 'wrote:': 0.17; 'instance,': 0.17; 'creates': 0.18; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'order.': 0.27; 'start,': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'record': 0.28; 'dictionary': 0.29; 'strings,': 0.29; 'fri,': 0.30; 'function': 0.30; 'code': 0.31; 'could': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'nov': 0.35; 'returning': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'depends': 0.36; 'should': 0.36; 'too': 0.36; 'being': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'personally': 0.61; 'skip:n 10': 0.63; 'become': 0.65; 'treat': 0.65; 'furman': 0.84; 'stop,': 0.84; 'ethan': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Ch8j4IAIgAClhXof8WWgxGMlaBEHrS/BKSWJoX0cTH0=; b=ZPP3ACvFFUSIOF4vyFAUWUPXpM43u1NJS3VhWm+73w/9VKmk/0SfxuHKpMZBNKfMqN ftCMArsqOHFYld7FebQC6NBUya5Z5fegNengdvV4zR9RyNgu6KVqg3TlhRqUFJNl7xg+ QsqobCgXJiyK1dWnrBoOomCBUImQXrDH8EfMld8Ot9mRhELkAgn8ll2AyOJfgySBD8Vi 81+deKbraXo8cm5++KAOums42jFNhvGx+dlvrLe3+ueEOO6mUciwHIre+aWMCjZ+SIKJ ue6qknOKACFBVPs85sFmQ4Wlcraae8govC53fJ90baTND+ZaxbjGE4gTpME3i4M1pkiD XLRg== |
| MIME-Version | 1.0 |
| In-Reply-To | <5092833F.4070609@stoneleaf.us> |
| References | <509053F2.6020900@r3dsolutions.com> <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 | Fri, 2 Nov 2012 01:40:22 +1100 |
| Subject | Re: Negative array indicies and slice() |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3150.1351780831.27098.python-list@python.org> (permalink) |
| Lines | 24 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1351780831 news.xs4all.nl 6982 [2001:888:2000:d::a6]:58477 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:32560 |
Show key headers only | View raw
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