[Tutor] When are strings interned?

2009-07-01 Thread Angus Rodgers
stem (using IDLE): >>> n = "colourless" >>> o = "colourless" >>> n == o True >>> n is o True >>> p = "green ideas" >>> q = "green ideas" >>> p == q True >>> p is q False Why the differe

[Tutor] Floor and modulus for complex arguments

2009-07-03 Thread Angus Rodgers
there been heated debate about this (e.g. in the context of Python 3, where the change to the division operator has apparently already provoked heated debate)? Also, by the way, is there some obvious reason for Python's use of the notation x + yj, rather than the more standard (except per

Re: [Tutor] When are strings interned?

2009-07-03 Thread Angus Rodgers
This is partly a test to see if I can reply in the correct format to a message in the tutor list (which I receive in digest format). >Date: Thu, 02 Jul 2009 20:39:28 +1000 >From: Lie Ryan > >Angus Rodgers wrote: >[...] >>>>> p = "green ideas" >>>

Re: [Tutor] When are strings interned?

2009-07-03 Thread Angus Rodgers
This is partly a test to see if I can reply in the correct format to a message in the tutor list (which I receive in digest format). >Date: Thu, 02 Jul 2009 20:39:28 +1000 >From: Lie Ryan > >Angus Rodgers wrote: >[...] >>>>> p = "green ideas" >>>

[Tutor] Apology (was:When are strings interned?)

2009-07-03 Thread Angus Rodgers
>Date: Fri, 03 Jul 2009 12:46:06 +0100 >From: Angus Rodgers >To: tutor@python.org >Subject: Re: [Tutor] When are strings interned? >Message-ID: >Content-Type: text/plain; charset=us-ascii >[...] >Date: Fri, 03 Jul 2009 14:43:21 +0100 >From: Angus Rodgers >To:

Re: [Tutor] Floor and modulus for complex arguments

2009-07-03 Thread Angus Rodgers
>Date: Sat, 04 Jul 2009 00:25:13 +1000 >From: Lie Ryan >Message-ID: > >Angus Rodgers wrote: > >> I /think/ I would be naturally inclined to define: >> >> floor(x + yj) = floor(x) + floor(y)j for all real x, y >> >> z % w = z - floor(z / w)

[Tutor] Is my style OK in this elementary student exercise?

2009-07-04 Thread Angus Rodgers
about ("unknown unknowns"). Any comments? (I don't expect the Spanish Inquisition!) -- Angus Rodgers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Is my style OK in this elementary student exercise?

2009-07-04 Thread Angus Rodgers
>Date: Sat, 04 Jul 2009 13:26:12 +0100 >From: Angus Rodgers >Message-ID: > ><http://python.pastebin.com/d7e245e0f> (retention: 1 day) This is just a quick(ish!) response to the feedback so far. I realise, now, that I should have quoted what the exercise in the book was a

Re: [Tutor] Is my style OK in this elementary student exercise?

2009-07-04 Thread Angus Rodgers
typ.__name__ >else: # User has provided an object of the correct type > ans[key] = val >return ans > I don't see this, because, if an exception does occur, won't there be an attempt to access one of the objects 'key', 'val' before

[Tutor] Poor style to use list as "array"?

2009-07-05 Thread Angus Rodgers
ies instead, with the denomination names as keys? Is it possible to guarantee a sequence in which the keys of a dictionary are iterated through? (If not, I suppose I could keep the list 'denom' as it is here, and iterate through it with "for key in denom:", although this seems a b

Re: [Tutor] Poor style to use list as "array"?

2009-07-05 Thread Angus Rodgers
On Sun, 5 Jul 2009 18:49:32 -0400, Kent Johnson wrote: >On Sun, Jul 5, 2009 at 2:48 PM, Angus Rodgers wrote: > >> for i in range(LEN - 1): >>    (count[i], amnt) = divmod(amnt, value[i]) Incidentally, I forgot to quote the next line: count[-1] = m Of course, this is much b

Re: [Tutor] Poor style to use list as "array"?

2009-07-05 Thread Angus Rodgers
;(count, amnt) = divmod(amnt, val) >counts[val] = count Better, of course (I still haven't run it, but it should work): counts = {} for val in value: (counts[val], amnt) = divmod(amnt, val) >I'm much happier now, thanks! ... but also rather annoyed with myself.

Re: [Tutor] Poor style to use list as "array"?

2009-07-06 Thread Angus Rodgers
Thanks to all of you. I haven't adopted the suggestion of using classes, which I think I'll leave for when I'm reading the later chapters of the book (although I do get the gist of the idea). -- Angus Rodgers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Python Tutorials: How to create useful programs

2009-07-09 Thread Angus Rodgers
a...@bermanrl-desktop> > >While it is not a sales pitch, the book is excellent. It and the Python >Cookbook sit on top of my desk. Both are fantastic and pragmatic >reference sources. >>> happy.append(me) >>> len(happy) 5 -- Angus Rodgers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Fwd: thesaurus

2009-07-09 Thread Angus Rodgers
lies like a banana. -- Angus Rodgers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Searching backwards from end of string

2009-07-10 Thread Angus Rodgers
return i return -1 def subchr(strng, origchar, newchar): chars = list(strng) for i, c in enumerate(chars): if c == origchar: chars[i] = newchar return ''.join(chars) I've quoted all my code, in case it's all

Re: [Tutor] Searching backwards from end of string

2009-07-10 Thread Angus Rodgers
#x27;abcdeefghijkl' BINGO. Done. > >Is that not a bit simpler I did explain (perhaps at too great a length, or with too many irrelevancies): >On Fri, 2009-07-10 at 16:24 +0100, Angus Rodgers wrote: >> [...] >> On the earlier occasion: >> [...] >> I wrote: >&

[Tutor] Trickier exercise: convert string to complex number

2009-07-10 Thread Angus Rodgers
if ch in '+-' and num[i] not in 'eE': return complex(float(num[:i + 1]), float(num[i + 1:-1])) return complex(float(num), 0.0) -- Angus Rodgers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Searching backwards from end of string

2009-07-11 Thread Angus Rodgers
use it in this one), and then the bit in the second message where I repeated this information, carefully and briefly, because you seemed to have missed it the first time! I hope I'm not being rude, but I just don't know what else to say. I can't see that I'

Re: [Tutor] Trickier exercise: convert string to complex number

2009-07-11 Thread Angus Rodgers
# Case (iv) return complex(float(num[:i + 1]), -float(num[i + 2:-1])) # Case (i) return complex(float(num), 0.0) (I have manually wrapped a few longish lines, just for this post to the mailing list - the longest was 76 characters long. I've also corrected another bug that was in the original program - it didn't check that the final [non-space] character was actually a 'j'.) -- Angus Rodgers ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor