[Tutor] True and 1 [was Re: use of the newer dict types]

2013-07-26 Thread Steven D'Aprano
On 27/07/13 08:48, Alan Gauld wrote: On 26/07/13 22:55, Jim Mooney wrote: And using True in place of 1 is sneakily pedagogical ;') It's not 'in place of' 1, it is a totally different value and type. It's only a happy coincidence that bool(1) returns True. So does bool(-9) after all... It

Re: [Tutor] use of the newer dict types

2013-07-26 Thread Alan Gauld
On 26/07/13 22:55, Jim Mooney wrote: bigBox = [ {1:2,3:4}, ['a',2,;freddy',True], (1,2,3) ] That is totally cool. I see something here every day that I know will be useful. Although Python choked on the semicolon in front of freddy. Oops, my bad. It should, of course be a quote sign. And

Re: [Tutor] Rock, Paper, Scissors game

2013-07-26 Thread Alan Gauld
On 26/07/13 12:22, Saad Javed wrote: WEAPONS = 'Rock', 'Paper', 'Scissors' if cpu != player: if (player - cpu) % 3 < (cpu - player) % 3: #How does this line work? Try it in the interpreter... the two subtractions will always result in +/-1 or +/-2 >>> -2 % 3 1 >>> 2 % 3 2 >>> -1 % 3

Re: [Tutor] Rock, Paper, Scissors game

2013-07-26 Thread Dave Angel
On 07/26/2013 07:22 AM, Saad Javed wrote: I'm trying to understand how this code works. I've commented the line that I can't seem to understand. How did the guy come up with this? #!/usr/bin/env python import random #rock > scissor > paper > rock WEAPONS = 'Rock', 'Paper', 'Scissors' for i i

Re: [Tutor] use of the newer dict types

2013-07-26 Thread Alan Gauld
On 26/07/13 09:50, Albert-Jan Roskam wrote: if I have d = {1: 2}, I can do membership testing in the following > two ways --but which one is the preferred way?: if 1 in d: pass if d.has_key(1): pass In addition to being more readable (and the fact it's the only way in v3) 'in' h