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] 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

Re: [Tutor] use of the newer dict types

2013-07-25 Thread Steven D'Aprano
On 26/07/13 07:49, Jim Mooney wrote: If you do dict.keys() in 2.7 you get a list, which is quite handy. But if you do it in 3.3 you get this odd dict_keys type, for which I have yet to find a use, and which just requires an extra list step to use. The same for values. Since most changes from 2.7

Re: [Tutor] use of the newer dict types

2013-07-25 Thread Dave Angel
On 07/25/2013 09:27 PM, eryksun wrote: On Thu, Jul 25, 2013 at 7:51 PM, Dave Angel wrote: And it's apparently safe to change the dictionary after creating the view, UNTIL the iterator is created. Notice the error the iterator raised in my example was just about the dict changing size. If the

Re: [Tutor] use of the newer dict types

2013-07-25 Thread Dave Angel
On 07/25/2013 06:54 PM, eryksun wrote: On Thu, Jul 25, 2013 at 6:37 PM, Dave Angel wrote: For dictionaries, instead of returning a list, keys() returns a dictionary view. See http://docs.python.org/3/library/stdtypes.html#dict-views What's not clear to me is whether this dictionary view obje

Re: [Tutor] use of the newer dict types

2013-07-25 Thread Dave Angel
On 07/25/2013 05:49 PM, Jim Mooney wrote: If you do dict.keys() in 2.7 you get a list, which is quite handy. But if you do it in 3.3 you get this odd dict_keys type, for which I have yet to find a use, and which just requires an extra list step to use. The same for values. Since most changes from