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


Groups > comp.lang.python > #65346

Re: [newbie] troubles with tuples

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <larry.martell@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'subject:: [': 0.04; 'element': 0.07; 'indices': 0.07; 'advance': 0.07; '-larry': 0.09; '(1,': 0.16; 'examples:': 0.16; 'surprises': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'subject:] ': 0.20; 'feb': 0.22; 'to:name:python-list@python.org': 0.22; 'mon,': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'rest': 0.29; 'am,': 0.29; 'array': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'gives': 0.31; 'jean': 0.31; 'tuples': 0.31; 'beginning': 0.33; 'subject:with': 0.35; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; 'should': 0.36; 'two': 0.37; 'expected': 0.38; 'e.g.': 0.38; 'to:addr:python- list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'first': 0.61; 'address': 0.63; 'kind': 0.63; 'here': 0.66
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=Exd6ykWdHRp9Ckp3h52VTDPDT2ZkE7cOLkyta6wLgtk=; b=J5Les9ok98U47zJDHH32ATWj13Gi5yVySlqrb0EgzfJN2TmUhfmF4yqO55ZQ3sf6CH tmoNauW67AtQgA+ct+rPfe+LSwmLIvrcYpUj8DGyYxTNLDTA6brjWtSD96lyYiO9Ww/o QKIZJx5LGPVQSyN6vQFT6L0/fOaMGeBoxgIER3QupOB2XnMK28YTLxWKNFRt+vxCwJmv jsG8tdbSp+vcXcp2j5YY7Ikxz4WqT6JUr3cMOhccZYlPZaawFTidanIZXJqvspIUlxhG EHUz4jYF/YZGUXcOA/pRGMXtTrePfWhKklcDEzR2uCA/3Fu4FroWtS4PtKPo5QUtfkBO YSag==
MIME-Version 1.0
X-Received by 10.229.193.136 with SMTP id du8mr24420789qcb.11.1391446833814; Mon, 03 Feb 2014 09:00:33 -0800 (PST)
In-Reply-To <893ced1a-dd55-48d7-8849-b2e45da2740e@googlegroups.com>
References <893ced1a-dd55-48d7-8849-b2e45da2740e@googlegroups.com>
Date Mon, 3 Feb 2014 12:00:33 -0500
Subject Re: [newbie] troubles with tuples
From Larry Martell <larry.martell@gmail.com>
To "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6345.1391446843.18130.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1391446843 news.xs4all.nl 2880 [2001:888:2000:d::a6]:59914
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:65346

Show key headers only | View raw


On Mon, Feb 3, 2014 at 11:50 AM, Jean Dupont <jeandupont314@gmail.com> wrote:
> I'm looking at the way to address tuples
> e.g.
> tup2 = (1, 2, 3, 4, 5, 6, 7 );
>
> As I found out indices start with 0 in Python, so
> tup2[0] gives me 1, the first element in the tuple as expected
> tup2[1] gives me 2, the second element in the tuple as expected
> now here comes what surprises me:
> tup2[0:1] does not give me the expected (1,2) but (2,)
>
> what is the reason for this and how then should one get the first and the second element of a tuple? Or the 3rd until the 5th?
>
> thanks in advance and kind regards,

Some examples:

a[start:end]  # items start through end-1
a[start:]       # items start through the rest of the array
a[:end]        # items from the beginning through end-1
a[:]             # a copy of the whole array
a[-1]           # last item in the array
a[-2:]          # last two items in the array
a[:-2]          # everything except the last two items

HTH,
-larry

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[newbie] troubles with tuples Jean Dupont <jeandupont314@gmail.com> - 2014-02-03 08:50 -0800
  Re: [newbie] troubles with tuples Asaf Las <roegltd@gmail.com> - 2014-02-03 08:59 -0800
  Re: [newbie] troubles with tuples Larry Martell <larry.martell@gmail.com> - 2014-02-03 12:00 -0500
  Re: [newbie] troubles with tuples Rustom Mody <rustompmody@gmail.com> - 2014-02-03 09:06 -0800
    Re: [newbie] troubles with tuples Jean Dupont <jeandupont314@gmail.com> - 2014-02-03 11:18 -0800
  Re: [newbie] troubles with tuples Terry Reedy <tjreedy@udel.edu> - 2014-02-03 16:52 -0500
  Re: [newbie] troubles with tuples Denis McMahon <denismfmcmahon@gmail.com> - 2014-02-04 00:50 +0000

csiph-web