Re: save dictionary to a file without brackets.

2012-08-14 Thread Mark Lawrence
On 14/08/2012 03:54, Steven D'Aprano wrote: On Mon, 13 Aug 2012 18:07:26 +0100, Mark Lawrence wrote: On 13/08/2012 17:14, alex23 wrote: On Aug 13, 10:37 pm, Mark Lawrence breamore...@yahoo.co.uk wrote: Why on your say so? My mistake, I didn't realise you wanted to sound so tedious. Knock

Re: save dictionary to a file without brackets.

2012-08-14 Thread Alister
On Tue, 14 Aug 2012 12:33:20 +0100, Mark Lawrence wrote: On 14/08/2012 03:54, Steven D'Aprano wrote: On Mon, 13 Aug 2012 18:07:26 +0100, Mark Lawrence wrote: On 13/08/2012 17:14, alex23 wrote: On Aug 13, 10:37 pm, Mark Lawrence breamore...@yahoo.co.uk wrote: Why on your say so? My

Re: save dictionary to a file without brackets.

2012-08-14 Thread Mark Lawrence
On 14/08/2012 16:05, Alister wrote: On Tue, 14 Aug 2012 12:33:20 +0100, Mark Lawrence wrote: On 14/08/2012 03:54, Steven D'Aprano wrote: On Mon, 13 Aug 2012 18:07:26 +0100, Mark Lawrence wrote: On 13/08/2012 17:14, alex23 wrote: On Aug 13, 10:37 pm, Mark Lawrence breamore...@yahoo.co.uk

Re: save dictionary to a file without brackets.

2012-08-13 Thread Steven D'Aprano
On Sun, 12 Aug 2012 17:15:12 -0700, alex23 wrote: On Aug 10, 7:37 pm, Mark Lawrence breamore...@yahoo.co.uk wrote: Well whatever you do *DON'T* mention Cython. I mentioned it just now but I think I've got away with it. While I'm not against threads straying off topic, you're beginning to

Re: save dictionary to a file without brackets.

2012-08-13 Thread Mark Lawrence
On 13/08/2012 01:15, alex23 wrote: On Aug 10, 7:37 pm, Mark Lawrence breamore...@yahoo.co.uk wrote: Well whatever you do *DON'T* mention Cython. I mentioned it just now but I think I've got away with it. While I'm not against threads straying off topic, you're beginning to come across as a

Re: save dictionary to a file without brackets.

2012-08-13 Thread alex23
On Aug 13, 10:37 pm, Mark Lawrence breamore...@yahoo.co.uk wrote: Why on your say so? My mistake, I didn't realise you wanted to sound so tedious. Knock yourself out. -- http://mail.python.org/mailman/listinfo/python-list

Re: save dictionary to a file without brackets.

2012-08-13 Thread alex23
On Aug 13, 6:05 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: Chill out Alex, it's all good. Mark was channelling a famous scene from Fawlty Towers, staring Monty Python's own John Cleese, hence it is on- topic, for the sillier definitions of on-topic. Thank you, yes, I get

Re: save dictionary to a file without brackets.

2012-08-13 Thread rusi
On Aug 13, 1:05 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: Chill out Alex, it's all good. Mark was channelling a famous scene from Fawlty Towers, staring Monty Python's own John Cleese, hence it is on- topic, for the sillier definitions of on-topic. Ha! Thanks for that

Re: save dictionary to a file without brackets.

2012-08-13 Thread Mark Lawrence
On 13/08/2012 17:14, alex23 wrote: On Aug 13, 10:37 pm, Mark Lawrence breamore...@yahoo.co.uk wrote: Why on your say so? My mistake, I didn't realise you wanted to sound so tedious. Knock yourself out. Yes m'lud. Do I lick your boots or polish them? -- Cheers. Mark Lawrence. --

Re: save dictionary to a file without brackets.

2012-08-13 Thread Mark Lawrence
On 13/08/2012 01:15, alex23 wrote: On Aug 10, 7:37 pm, Mark Lawrence breamore...@yahoo.co.uk wrote: Well whatever you do *DON'T* mention Cython. I mentioned it just now but I think I've got away with it. While I'm not against threads straying off topic, you're beginning to come across as a

Re: save dictionary to a file without brackets.

2012-08-13 Thread alex23
On Aug 14, 3:43 am, Mark Lawrence breamore...@yahoo.co.uk wrote: On 13/08/2012 01:15, alex23 wrote: On Aug 10, 7:37 pm, Mark Lawrence breamore...@yahoo.co.uk wrote: Well whatever you do *DON'T* mention Cython. I mentioned it just now but I think I've got away with it. While I'm not

Re: save dictionary to a file without brackets.

2012-08-13 Thread Steven D'Aprano
On Mon, 13 Aug 2012 18:07:26 +0100, Mark Lawrence wrote: On 13/08/2012 17:14, alex23 wrote: On Aug 13, 10:37 pm, Mark Lawrence breamore...@yahoo.co.uk wrote: Why on your say so? My mistake, I didn't realise you wanted to sound so tedious. Knock yourself out. Yes m'lud. Do I lick your

Re: save dictionary to a file without brackets.

2012-08-12 Thread 88888 Dihedral
Steven D'Aprano於 2012年8月11日星期六UTC+8下午7時26分37秒寫道: On Fri, 10 Aug 2012 08:53:43 +1000, Chris Angelico wrote: On Fri, Aug 10, 2012 at 8:26 AM, Dave Angel d...@davea.name wrote: On 08/09/2012 06:03 PM, Andrew Cooper wrote: O(n) for all other entries in the dict which suffer a hash

Re: save dictionary to a file without brackets.

2012-08-12 Thread alex23
On Aug 10, 7:37 pm, Mark Lawrence breamore...@yahoo.co.uk wrote: Well whatever you do *DON'T* mention Cython. I mentioned it just now but I think I've got away with it. While I'm not against threads straying off topic, you're beginning to come across as a bit of an asshole now. Just let it go.

Re: save dictionary to a file without brackets.

2012-08-11 Thread Steven D'Aprano
On Fri, 10 Aug 2012 08:53:43 +1000, Chris Angelico wrote: On Fri, Aug 10, 2012 at 8:26 AM, Dave Angel d...@davea.name wrote: On 08/09/2012 06:03 PM, Andrew Cooper wrote: O(n) for all other entries in the dict which suffer a hash collision with the searched entry. True, a sensible choice of

Re: save dictionary to a file without brackets.

2012-08-10 Thread Steven D'Aprano
On Thu, 09 Aug 2012 19:16:58 -0500, Tim Chase wrote: On 08/09/12 18:33, Mark Lawrence wrote: On 10/08/2012 00:24, Roy Smith wrote: ... you mean, Python lets you make a hash of it? Only if you order it with spam, spam, spam, spam, spam, spam, and spam. Now now gentlemen we're getting

Re: save dictionary to a file without brackets.

2012-08-10 Thread Mark Lawrence
On 10/08/2012 09:54, Steven D'Aprano wrote: On Thu, 09 Aug 2012 19:16:58 -0500, Tim Chase wrote: On 08/09/12 18:33, Mark Lawrence wrote: On 10/08/2012 00:24, Roy Smith wrote: ... you mean, Python lets you make a hash of it? Only if you order it with spam, spam, spam, spam, spam, spam, and

Re: save dictionary to a file without brackets.

2012-08-10 Thread Roy Smith
In article mailman.3147.1344591354.4697.python-l...@python.org, Mark Lawrence breamore...@yahoo.co.uk wrote: On 10/08/2012 09:54, Steven D'Aprano wrote: On Thu, 09 Aug 2012 19:16:58 -0500, Tim Chase wrote: On 08/09/12 18:33, Mark Lawrence wrote: On 10/08/2012 00:24, Roy Smith wrote:

Re: save dictionary to a file without brackets.

2012-08-10 Thread Mark Lawrence
On 10/08/2012 13:29, Roy Smith wrote: In article mailman.3147.1344591354.4697.python-l...@python.org, Mark Lawrence breamore...@yahoo.co.uk wrote: On 10/08/2012 09:54, Steven D'Aprano wrote: On Thu, 09 Aug 2012 19:16:58 -0500, Tim Chase wrote: On 08/09/12 18:33, Mark Lawrence wrote: On

Re: save dictionary to a file without brackets.

2012-08-10 Thread 88888 Dihedral
Dave Angel於 2012年8月10日星期五UTC+8上午5時47分45秒寫道: On 08/09/2012 05:34 PM, Roman Vashkevich wrote: Actually, they are different. Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. Dict uses hashing to get a value from

save dictionary to a file without brackets.

2012-08-09 Thread giuseppe . amatulli
Hi, I have a dict() unique like this {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? 4 5 1 5 4 1 4 4 2 2 3 1 4 3 2 Any ideas? Thanks in advance Giuseppe --

Re: save dictionary to a file without brackets.

2012-08-09 Thread Roman Vashkevich
for key in dict: print key[0], key[1], dict[key] 10.08.2012, в 0:11, giuseppe.amatu...@gmail.com написал(а): Hi, I have a dict() unique like this {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} and i want to print to a file without the brackets comas and semicolon in order to

Re: save dictionary to a file without brackets.

2012-08-09 Thread Oscar Benjamin
On Aug 9, 2012 9:17 PM, giuseppe.amatu...@gmail.com wrote: Hi, I have a dict() unique like this {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? 4 5 1 5 4 1 4 4 2 2 3 1

Re: save dictionary to a file without brackets.

2012-08-09 Thread Tim Chase
On 08/09/12 15:22, Roman Vashkevich wrote: {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? 4 5 1 5 4 1 4 4 2 2 3 1 4 3 2 for key in dict: print key[0], key[1],

Re: save dictionary to a file without brackets.

2012-08-09 Thread Giuseppe Amatulli
thanks for the fast replies my testing were very closed to yours but i did not know how On 9 August 2012 15:25, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On Aug 9, 2012 9:17 PM, giuseppe.amatu...@gmail.com wrote: Hi, I have a dict() unique like this {(4, 5): 1, (5, 4): 1, (4, 4): 2,

Re: save dictionary to a file without brackets.

2012-08-09 Thread Giuseppe Amatulli
thanks for the fast replies my testing were very closed to yours but i did not know how to print the the number after the semicolon! thanks! On 9 August 2012 15:25, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On Aug 9, 2012 9:17 PM, giuseppe.amatu...@gmail.com wrote: Hi, I have a

Re: save dictionary to a file without brackets.

2012-08-09 Thread Gelonida N
On 08/09/2012 10:11 PM, giuseppe.amatu...@gmail.com wrote: Hi, I have a dict() unique like this {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} and i want to print to a file without the brackets comas and semicolon in order to obtain something like this? 4 5 1 5 4 1 4 4 2 2 3 1 4 3 2

Re: save dictionary to a file without brackets.

2012-08-09 Thread Roman Vashkevich
dict.items() is a list - linear access time whereas with 'for key in dict:' access time is constant: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#use-in-where-possible-1 10.08.2012, в 0:35, Tim Chase написал(а): On 08/09/12 15:22, Roman Vashkevich wrote: {(4, 5): 1,

Re: save dictionary to a file without brackets.

2012-08-09 Thread Mark Lawrence
On 09/08/2012 21:41, Roman Vashkevich wrote: dict.items() is a list - linear access time whereas with 'for key in dict:' access time is constant: http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#use-in-where-possible-1 10.08.2012, в 0:35, Tim Chase написал(а): On

Re: save dictionary to a file without brackets.

2012-08-09 Thread Tim Chase
On 08/09/12 15:41, Roman Vashkevich wrote: 10.08.2012, в 0:35, Tim Chase написал(а): On 08/09/12 15:22, Roman Vashkevich wrote: {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} and i want to print to a file without the brackets comas and semicolon in order to obtain something like

Re: save dictionary to a file without brackets.

2012-08-09 Thread Roman Vashkevich
Actually, they are different. Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. Dict uses hashing to get a value from the dict and this is why it's O(1). 10.08.2012, в 1:21, Tim Chase написал(а): On 08/09/12 15:41, Roman

Re: save dictionary to a file without brackets.

2012-08-09 Thread Terry Reedy
On 8/9/2012 5:21 PM, Tim Chase wrote: On 08/09/12 15:41, Roman Vashkevich wrote: 10.08.2012, в 0:35, Tim Chase написал(а): On 08/09/12 15:22, Roman Vashkevich wrote: {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} and i want to print to a file without the brackets comas and semicolon

Re: save dictionary to a file without brackets.

2012-08-09 Thread Dave Angel
On 08/09/2012 05:34 PM, Roman Vashkevich wrote: Actually, they are different. Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. Dict uses hashing to get a value from the dict and this is why it's O(1). Sure, that's why

Re: save dictionary to a file without brackets.

2012-08-09 Thread Chris Kaynor
I realized, I should have done 10, 100, 1000 rather than 1, 10, 100 for better results, so here are the results for 1000 items. It still maintains the same pattern: timeit.timeit('for i in d: pass', 'd=dict.fromkeys(range(1000))') 10.166595947685153 timeit.timeit('for i in d.iteritems(): pass',

Re: save dictionary to a file without brackets.

2012-08-09 Thread Chris Kaynor
On Thu, Aug 9, 2012 at 2:34 PM, Roman Vashkevich vashkevic...@gmail.com wrote: Actually, they are different. Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. Dict uses hashing to get a value from the dict and this is

Re: save dictionary to a file without brackets.

2012-08-09 Thread Giuseppe Amatulli
Thanks a lot for the clarification. Actually my problem is giving to raster dataset in geo-tif format find out unique pair combination, count the number of observation unique combination in rast1, count the number of observation unique combination in rast2, count the number of observation I try

Re: save dictionary to a file without brackets.

2012-08-09 Thread Roman Vashkevich
10.08.2012, в 1:47, Dave Angel написал(а): On 08/09/2012 05:34 PM, Roman Vashkevich wrote: Actually, they are different. Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. Dict uses hashing to get a value from the dict

Re: save dictionary to a file without brackets.

2012-08-09 Thread Andrew Cooper
On 09/08/2012 22:34, Roman Vashkevich wrote: Actually, they are different. Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. Dict uses hashing to get a value from the dict and this is why it's O(1). Sligtly off topic,

Re: save dictionary to a file without brackets.

2012-08-09 Thread Dave Angel
On 08/09/2012 06:03 PM, Andrew Cooper wrote: On 09/08/2012 22:34, Roman Vashkevich wrote: Actually, they are different. Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. Dict uses hashing to get a value from the dict and

Re: save dictionary to a file without brackets.

2012-08-09 Thread Tim Chase
On 08/09/12 17:26, Dave Angel wrote: On 08/09/2012 06:03 PM, Andrew Cooper wrote: I'm glad you're wrong for CPython's dictionaries. The only time the lookup would degenerate to O[n] would be if the hash table had only one slot. CPython sensibly increases the hash table size when it becomes

Re: save dictionary to a file without brackets.

2012-08-09 Thread Chris Kaynor
On Thu, Aug 9, 2012 at 3:26 PM, Dave Angel d...@davea.name wrote: On 08/09/2012 06:03 PM, Andrew Cooper wrote: On 09/08/2012 22:34, Roman Vashkevich wrote: Actually, they are different. Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel

Re: save dictionary to a file without brackets.

2012-08-09 Thread Chris Angelico
On Fri, Aug 10, 2012 at 8:26 AM, Dave Angel d...@davea.name wrote: On 08/09/2012 06:03 PM, Andrew Cooper wrote: O(n) for all other entries in the dict which suffer a hash collision with the searched entry. True, a sensible choice of hash function will reduce n to 1 in common cases, but it

Re: save dictionary to a file without brackets.

2012-08-09 Thread Andrew Cooper
On 09/08/2012 23:26, Dave Angel wrote: On 08/09/2012 06:03 PM, Andrew Cooper wrote: On 09/08/2012 22:34, Roman Vashkevich wrote: Actually, they are different. Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. Dict uses

Re: save dictionary to a file without brackets.

2012-08-09 Thread Chris Angelico
On Fri, Aug 10, 2012 at 8:39 AM, Tim Chase python.l...@tim.thechases.com wrote: On 08/09/12 17:26, Dave Angel wrote: On 08/09/2012 06:03 PM, Andrew Cooper wrote: I'm glad you're wrong for CPython's dictionaries. The only time the lookup would degenerate to O[n] would be if the hash table had

Re: save dictionary to a file without brackets.

2012-08-09 Thread Oscar Benjamin
What do you think? is there a way to speed up the process? Thanks Giuseppe Which part is slow? How slow is it? A simple test to find the slow part of your code is to print messages between the commands so that you can see how long it takes between each message. Oscar. --

Re: save dictionary to a file without brackets.

2012-08-09 Thread Roy Smith
In article ucXUr.1030527$2z2.380746@fx19.am4, Andrew Cooper am...@cam.ac.uk wrote: As for poor implementations, class Foo(object): def __hash__(self): return 0 I seriously found that in some older code I had the misfortune of reading. Python assumes you are a consenting

Re: save dictionary to a file without brackets.

2012-08-09 Thread Chris Angelico
On Fri, Aug 10, 2012 at 9:05 AM, Roy Smith r...@panix.com wrote: Python assumes you are a consenting adult. If you wish to engage in activities which are hazardous to your health, so be it. ... you mean, Python lets you make a hash of it? *ducks for cover* ChrisA --

Re: save dictionary to a file without brackets.

2012-08-09 Thread Roy Smith
In article mailman.3135.1344554073.4697.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Fri, Aug 10, 2012 at 9:05 AM, Roy Smith r...@panix.com wrote: Python assumes you are a consenting adult. If you wish to engage in activities which are hazardous to your health, so be

Re: save dictionary to a file without brackets.

2012-08-09 Thread Mark Lawrence
On 10/08/2012 00:24, Roy Smith wrote: In article mailman.3135.1344554073.4697.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Fri, Aug 10, 2012 at 9:05 AM, Roy Smith r...@panix.com wrote: Python assumes you are a consenting adult. If you wish to engage in activities which

Re: save dictionary to a file without brackets.

2012-08-09 Thread Dave Angel
On 08/09/2012 06:54 PM, Andrew Cooper wrote: On 09/08/2012 23:26, Dave Angel wrote: On 08/09/2012 06:03 PM, Andrew Cooper wrote: On 09/08/2012 22:34, Roman Vashkevich wrote: Actually, they are different. Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries,

Re: save dictionary to a file without brackets.

2012-08-09 Thread Dave Angel
On 08/09/2012 06:53 PM, Chris Angelico wrote: On Fri, Aug 10, 2012 at 8:26 AM, Dave Angel d...@davea.name wrote: On 08/09/2012 06:03 PM, Andrew Cooper wrote: O(n) for all other entries in the dict which suffer a hash collision with the searched entry. True, a sensible choice of hash function

Re: save dictionary to a file without brackets.

2012-08-09 Thread Oscar Benjamin
On Aug 10, 2012 12:34 AM, Giuseppe Amatulli giuseppe.amatu...@gmail.com wrote: Ciao, is 12 minutes for 5000x5000 pixel image. half of the time is for reading the arrays. and the other half for making the loop. I will try again to incorporate the mask action in the loop and read the image

Re: save dictionary to a file without brackets.

2012-08-09 Thread Tim Chase
On 08/09/12 18:33, Mark Lawrence wrote: On 10/08/2012 00:24, Roy Smith wrote: ... you mean, Python lets you make a hash of it? Only if you order it with spam, spam, spam, spam, spam, spam, and spam. Now now gentlemen we're getting slightly off topic here and wouldn't want to upset the

Re: save dictionary to a file without brackets.

2012-08-09 Thread Dave Angel
On 08/09/2012 08:16 PM, Tim Chase wrote: On 08/09/12 18:33, Mark Lawrence wrote: On 10/08/2012 00:24, Roy Smith wrote: ... you mean, Python lets you make a hash of it? Only if you order it with spam, spam, spam, spam, spam, spam, and spam. Now now gentlemen we're getting slightly off topic

Re: save dictionary to a file without brackets.

2012-08-09 Thread Chris Angelico
On Fri, Aug 10, 2012 at 10:16 AM, Tim Chase python.l...@tim.thechases.com wrote: We apologise for the off-topicness in the thread. Those responsible have been sacked... So if you take every mapping variable in your program and name them dFoo, dBar, dQuux, etc, for dict... would that be a dirty

Re: save dictionary to a file without brackets.

2012-08-09 Thread 88888 Dihedral
Andrew Cooper於 2012年8月10日星期五UTC+8上午6時03分26秒寫道: On 09/08/2012 22:34, Roman Vashkevich wrote: Actually, they are different. Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. Dict uses hashing to get a value from