Re: [Tutor] Tuple indexing

2015-03-12 Thread Ian D
. > To: tutor@python.org > From: __pete...@web.de > Date: Wed, 11 Mar 2015 16:35:09 +0100 > Subject: Re: [Tutor] Tuple indexing > > Ian D wrote: > >> Hi >> >> >> >> I have seen some examples that seem to use a tuple with a method called >

Re: [Tutor] Tuple indexing

2015-03-11 Thread Steven D'Aprano
On Wed, Mar 11, 2015 at 02:08:18PM +, Ian D wrote: [...] > I then read that a Tuple has no attribute index on this site > http://www.diveintopython.net/native_data_types/tuples.html That's pretty old, and written by an independent author. The official documentation for Python is here: https

Re: [Tutor] Tuple indexing

2015-03-11 Thread Peter Otten
Ian D wrote: > Hi > > > > I have seen some examples that seem to use a tuple with a method called > index() > > > The original code I was looking at had this sort of thing: > > > Hi Ian! Please don't use that much whitespace. It makes your post hard and unpleasant to read. Thank you. >

Re: [Tutor] Tuple indexing

2015-03-11 Thread Joel Goldstick
On Wed, Mar 11, 2015 at 10:08 AM, Ian D wrote: > Hi > > > > I have seen some examples that seem to use a tuple with a method called > index() > > > The original code I was looking at had this sort of thing: > > > > SENSORS = ('sensor1', 'sensor2') > > > SENSORS[0] > pin_index

Re: [Tutor] Tuple - Immutable ?

2012-03-08 Thread Steven D'Aprano
col speed wrote: On 8 March 2012 18:51, Steven D'Aprano wrote: This makes sense, and is easy to understand. Now for the real boggle: py> a = 9912346; b = 9912346 py> a is b True Can you guess what is going on here? (Answer will follow later.) Because it's on the same line and there are

Re: [Tutor] Tuple - Immutable ?

2012-03-08 Thread col speed
On 8 March 2012 19:18, John Jensen wrote: > > From: Steven D'Aprano > To: tutor@python.org > Sent: Thursday, March 8, 2012 7:51:33 AM > Subject: Re: [Tutor] Tuple - Immutable ? > > col speed wrote: > >> I was just thinking a

Re: [Tutor] Tuple - Immutable ?

2012-03-08 Thread John Jensen
From: Steven D'Aprano To: tutor@python.org Sent: Thursday, March 8, 2012 7:51:33 AM Subject: Re: [Tutor] Tuple - Immutable ? col speed wrote: > I was just thinking about the immutability of things and tried this > (which -at least I- find

Re: [Tutor] Tuple - Immutable ?

2012-03-08 Thread col speed
On 8 March 2012 18:51, Steven D'Aprano wrote: > col speed wrote: > >> I was just thinking about the immutability of things and tried this >> (which -at least I- find interesting: >> > id(1) >> >> 154579120 > > a = 1 > id(a) >> >> 154579120 > > a += 2 > id(a) >> >> 15457

Re: [Tutor] Tuple - Immutable ?

2012-03-08 Thread Steven D'Aprano
col speed wrote: I was just thinking about the immutability of things and tried this (which -at least I- find interesting: id(1) 154579120 a = 1 id(a) 154579120 a += 2 id(a) 154579096 id(3) 154579096 a is 3 True Although there is probably no other logical way of doing it - I learnt so

Re: [Tutor] Tuple - Immutable ?

2012-03-08 Thread Sudip Bhattacharya
That makes perfect sense. What happened was that the old tuple got replaced with a new tuple (old + new items) and NOT changed cause tuple is immutable. Thanks HTH. On Thu, Mar 8, 2012 at 4:53 PM, col speed wrote: > On 8 March 2012 18:11, Sudip Bhattacharya wrote: > s=(1,2,3) > s=s+(

Re: [Tutor] Tuple - Immutable ?

2012-03-08 Thread col speed
On 8 March 2012 18:27, Walter Prins wrote: > Just to add, notice that even for lists, > > l = l + [7,8,9] > > produces a new list, while > > l += [7,8,9] > > does not. > ___ > Tutor maillist  -  Tutor@python.org > To unsubscribe or change subscription op

Re: [Tutor] Tuple - Immutable ?

2012-03-08 Thread col speed
On 8 March 2012 18:11, Sudip Bhattacharya wrote: s=(1,2,3) s=s+(4,5,6) s > (1,2,3,4,5,6) > > The tuple has changed. > > I thought I read that tuples are sequences (like lists), but they are > immutable - They can't be changed once created. Could someone explain please > ? I'm just a

Re: [Tutor] Tuple - Immutable ?

2012-03-08 Thread Walter Prins
Just to add, notice that even for lists, l = l + [7,8,9] produces a new list, while l += [7,8,9] does not. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Tuple - Immutable ?

2012-03-08 Thread Walter Prins
On 8 March 2012 11:11, Sudip Bhattacharya wrote: s=(1,2,3) s=s+(4,5,6) s > (1,2,3,4,5,6) > > The tuple has changed. No, the tuple hasn't changed. That's a *new* tuple. Consider: Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32 Type "copyright", "

Re: [Tutor] Tuple - Immutable ?

2012-03-08 Thread Steven D'Aprano
Sudip Bhattacharya wrote: s=(1,2,3) s=s+(4,5,6) s (1,2,3,4,5,6) The tuple has changed. No it hasn't. You have created a *new* tuple, and assigned it to the same name. Consider: py> s = (1, 2, 3) py> id(s) 3083421332 py> t = s py> id(t) 3083421332 This shows that both s and t are names fo

Re: [Tutor] Tuple: Am I Understanding This Correctly?

2011-12-14 Thread Alan Gauld
On 14/12/11 15:48, Homme, James wrote: Am I explaining how this works correctly? You are not really explaining *how* it works, just saying what it does. What you are doing is sensible iff you have many places where the tuple is useful. In the specific case I'd personally just create the tuple

Re: [Tutor] tuple & object's attributes (changed)

2009-01-02 Thread Alan Gauld
"Kent Johnson" wrote To actually *constrain* a collection to be homogeneous seems extremely un-pythonic. In actual fact all containers can hold whatever you want to put in them without restriction (except hashability requirements for sets and dict keys). And strings which are kind of a col

Re: [Tutor] tuple & object's attributes (changed)

2009-01-02 Thread bob gailer
Kent Johnson wrote: [snip] To actually *constrain* a collection to be homogeneous seems extremely un-pythonic. In actual fact all containers can hold whatever you want to put in them without restriction (except hashability requirements for sets and dict keys). Well, the array module offers o

Re: [Tutor] tuple & object's attributes (changed)

2009-01-02 Thread Andre Engels
On Fri, Jan 2, 2009 at 10:37 PM, Kent Johnson wrote: > Forwarding to the list with comments. > > On Fri, Jan 2, 2009 at 2:47 PM, spir wrote: >> Now, remains one major question: >> Why do lists hold heterogeneous items? (Why did Guido do that choice, and >> then assert that >> lists are for homo

Re: [Tutor] tuple & object's attributes (changed)

2009-01-02 Thread Kent Johnson
Forwarding to the list with comments. On Fri, Jan 2, 2009 at 2:47 PM, spir wrote: > On Fri, 2 Jan 2009 11:57:32 -0500 > "Kent Johnson" wrote: > >> On Fri, Jan 2, 2009 at 11:10 AM, spir wrote: >> > Can someone explain the following? >> > >> > >> > class Type(object):

Re: [Tutor] Tuple of Tuples

2008-10-11 Thread W W
On Sat, Oct 11, 2008 at 9:53 AM, Wayne Watson <[EMAIL PROTECTED]> wrote: > I would like to create a tuple of tuples. As I read (x,y) pairs I would like > to "add" them to others. In the example below, I seem to be picking up () > each time I augment the tuple t. > === t = () t

Re: [Tutor] Tuple and Dicts?

2006-11-09 Thread Kent Johnson
Basil Shubin wrote: > Hi friends! > > Imagine the tuple that has dictionaries as it's item: > print data > ({'id': 0, 'title': 'Linux'}, {'id': 1, 'title': 'FreeBSD'}) > > How I can get index of tuple item where dict's key 'id' equal to > appropriate value? And can this be done without 'for

Re: [Tutor] Tuple and Dicts?

2006-11-09 Thread Jason Massey
How about something like:>>> data = "" 0, 'title': 'Linux'}, {'id': 1, 'title': 'FreeBSD'})>>> id = 0>>> result = [x for x in data if x['id'] == id][{'id': 0, 'title': 'Linux'}] >>> result = [x for x in data if x['id'] == id]>>> result[0]{'id': 0, 'title': 'Linux'}>>> You get the entire dict entry

Re: [Tutor] Tuple (Section 9.3)

2006-04-11 Thread Hugo González Monteverde
Hi Kaushal, I might have to do a little guessing and see what is not clear from the explanation. The whole point of returning a tuple as opposed to, say, returning a list, is the fact that tuples are NON mutable. That is, *apparently* you would not be returning a reference, but the values themse

Re: [Tutor] Tuple (Section 9.3)

2006-04-11 Thread Hugo González Monteverde
Hi Kaushal, I might have to do a little guessing and see what is not clear from the explanation. The whole point of returning a tuple as opposed to, say, returning a list, is the fact that tuples are NON mutable. That is, *apparently* you would not be returning a reference, but the values the

Re: [Tutor] Tuple

2006-04-11 Thread Alan Gauld
>>> tuple = ('A',) + tuple[1:] >>> tuple >('A', 'b', 'c', 'd', 'e') > > How does tuple = ('A',) + tuple[1:] this work > > Please explain me with an example OK, we will use the example you gave us! tuple is a bad name since Python has an internal type called tuple usd for converting a list

Re: [Tutor] Tuple

2006-04-11 Thread Kaushal Shriyan
On 4/11/06, Noufal Ibrahim <[EMAIL PROTECTED]> wrote: > > On Tue, April 11, 2006 2:49 pm, Kaushal Shriyan wrote: > > Hi All > > > > I am referring to http://www.ibiblio.org/obp/thinkCSpy/chap09.htm > > > tuple = ('a', 'b', 'c', 'd', 'e') > tuple[0] > > 'a' > > > > > > And the slice operat

Re: [Tutor] Tuple

2006-04-11 Thread Noufal Ibrahim
On Tue, April 11, 2006 2:49 pm, Kaushal Shriyan wrote: > Hi All > > I am referring to http://www.ibiblio.org/obp/thinkCSpy/chap09.htm > tuple = ('a', 'b', 'c', 'd', 'e') tuple[0] > 'a' > > > And the slice operator selects a range of elements. > tuple[1:3] > ('b', 'c') > > > But if w