Re: using range() in for loops

2006-04-05 Thread Adam DePrince
On Tue, 2006-04-04 at 21:54 -0400, John Salerno wrote: > I'm reading Text Processing in Python right now and I came across a > comment that is helping me to see for loops in a new light. I think > because I'm used to the C-style for loop where you create a counter > within the loop declaration,

Re: Best IDE for Python?

2006-04-03 Thread Adam DePrince
On Fri, 2006-03-31 at 09:30 +0200, Fredrik Lundh wrote: > Dennis Lee Bieber wrote: > > > > I want to know which is the best IDE for python.Please if > > > possible mention the features of the IDE. > > > > The best IDE is the one that YOU can be most productive in. What /I/ > > find useful ma

Re: Newbie: splitting dictionary definition across two .py files

2006-04-03 Thread Adam DePrince
On Fri, 2006-03-31 at 12:46 -0800, Karthik Gurusamy wrote: > Ben Finney wrote: > > [EMAIL PROTECTED] writes: > > > > > I'm fairly new to python. I like to define a big dictionary in two > > > files and use it my main file, build.py > > > > > > I want the definition to go into build_cfg.py and build

Re: Difference between 'is' and '=='

2006-04-03 Thread Adam DePrince
ch street he would look the wrong way, look the correct way and then stare the wrong way again. Upon noticing my inquisitorial expression, he answered "A good programmer always looks both ways when crossing a one way street." I'm uncertain that a quip about abstracting away the rain would

Re: freeze.py and GTK apps

2006-03-28 Thread Adam DePrince
On Mon, 2006-03-27 at 16:15 -0800, [EMAIL PROTECTED] wrote: > After freezing a PYGTK app, I am unable to run it. It this a common > problem, because I could not find any documentation on it at all. > > I tried freezing this example, which gets by the make as well, but > running it results in a fa

Re: 1.090516455488E9 / 1000000.000 ???

2006-03-28 Thread Adam DePrince
516455488' >>> Works for me. Code snippet? Print does seem to round at 12 digits. >>> print 1.090516455488E9/100 1090.51645549 >>> Cheers - Adam DePrince > > I know something with float and //... > > Anybody? > How do I get correct number? -- http://mail.python.org/mailman/listinfo/python-list

Re: in-place string reversal

2006-03-28 Thread Adam DePrince
;Abc" >> myfancy_structre.add_somehow( s ) >> t = s[::-1] >> print s Abc >> print t cbA Now if strings were mutable: >> s = "Abc" >> myfancy_structre.add_somehow( s ) >> s.reverseme() >> print s cbA Other users of s between assignment and reversal (like myfancy_structure) might not be happy that is was reversed when they next must use it. Cheers - Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: wired md5 hashing problem

2006-03-26 Thread Adam DePrince
On Sun, 2006-03-26 at 16:56 +0200, Matthias Güntert wrote: > Hello list-members > > i am in the process of writing a python script to backup my data. Now I > would like to implement md5/sha1 hashes. > > # do md5 fingerprinting > if config.get("global", "crc") == "md5": > m = md

Re: wired md5 hashing problem

2006-03-26 Thread Adam DePrince
What do you get when you type md5sum backup.tar.bz2? - Adam On Sun, 2006-03-26 at 16:56 +0200, Matthias Güntert wrote: > Hello list-members > > i am in the process of writing a python script to backup my data. Now I > would like to implement md5/sha1 hashes. > > # do md5 fingerprinting

Re: Extending Methods Vs Delegates

2006-03-26 Thread Adam DePrince
On Sun, 2006-03-26 at 07:21 -0800, Alex Martelli wrote: > vbgunz <[EMAIL PROTECTED]> wrote: > > > I am sorry I couldn't reply sooner! Alex, Python in a nutshell is my > > bible and I take it virtually everywhere! Seriously, I would highly > > recommend it to anyone with a little to a lot of Python

PEP for nondeterminism.

2006-03-24 Thread Adam DePrince
The first calls for core language changes, the second calls for a minor (and likely symbolic) change to list comprehension's semantics to better support future parallelism. PEP: XXX Title: Nondeterminism Version: $Revision$ Last-Modified: $Date$ Author: Adam DePrince <[EMAIL PROTECTED]&g

Re: New Python logo in high resolution format

2006-03-24 Thread Adam DePrince
On Fri, 2006-03-24 at 10:49 -0800, Robert Hicks wrote: > How about we all get tatoos? : ) ... still trying to scrape the old one off ... > > Robert > -- http://mail.python.org/mailman/listinfo/python-list

Re: Incremental Compression

2006-03-24 Thread Adam DePrince
ing its memory of what it saw in the past. 3. Z_FINISH. This is the default action, this is what is killing you. Good luck - Adam DePrince > > I cannot wait until the end of the stream and then flush, because I need to > flush after every packet. > > Another capability I requ

Re: Caching in memory for Apache

2006-03-24 Thread Adam DePrince
for me to store > values inside memory so I can look it up on the next GET request? Your database really is the best place for that. Good luck - Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Multiplying all the values in a dictionary

2006-03-24 Thread Adam DePrince
Droppings from other timing tests; starbucks was kicking me out and I was in a hurry. Cheers - Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Bitwise OR?

2006-03-24 Thread Adam DePrince
On Fri, 2006-03-24 at 12:55 +0100, Clemens Hepper wrote: > Hello, > > I've written a little (optimized) method to get a bit-string: > > def bitstringneg(number, digits=32): > """optimized for negative numbers""" > result = "" > for a in xrange(digits): > if number & 1: > result +=

Re: overlapping sets

2006-03-23 Thread Adam DePrince
ut, but your biggest impediment is how you are looking at the problem. For reference http://www.python.org/doc/essays/graphs.html As for detecting neighboors, sure that's easy, but first you have to try to use a for loop first on your own to tell how many positional items any two lists differ by. Cheers and good luck - Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Multiplying all the values in a dictionary

2006-03-23 Thread Adam DePrince
Excuse me, I mean python2.4 -mtimeit -s 'from numarray import array; d = {(100,500):[5,5], (100,501):[6,6], (100,502):[7,7]}; x = dict(d);' 'for i in x.values(): i[0]*=1;i[1]*=1' 100 loops, best of 3: 1.72 usec per loop i[0]*=1, not j[0]*=1 ... -- http://mail.python.org/mailman/listinfo/p

Re: Multiplying all the values in a dictionary

2006-03-23 Thread Adam DePrince
Wait! It occured to me. Why are we touching the key at all. This is a dictionary with mutable values. [EMAIL PROTECTED] ~]$ python2.4 -mtimeit -s 'd = {(100,500):[5,5], (100,501):[6,6], (100,502):[7,7]}; x = dict(d)' 'for i in x.values(): i[:]=[j*1 for j in i]' 10 loops, best of 3: 2.79 us

Re: Multiplying all the values in a dictionary

2006-03-23 Thread Adam DePrince
Yes, I cede that explicit indexing is faster by quite a bit. There is a somewhat philosophical decision for why I avoided that. I prefer to try to present python with as big of a picture of what I want as possiable. update tells python what I want to do, whereas the for-loop describes how to. I

Re: Getting a loop to activate a loop above it

2006-03-23 Thread adam . deprince
This is how python is supposed to work. I'm sure not what languages you have used ... it seems that you are expecting some sort rule based system like make, or prolog. Grab a cup of joe, pull up a chair and let me help you out here. Python is an imperative language, you can envision the presence

Re: Multiplying all the values in a dictionary

2006-03-23 Thread adam . deprince
>for key in d: > d[key] = [x*2 for x in d[key]] > Naw, if you are going to use list interpolation go all the way and save yourself all of that ugly indexing into the dict. >>> d = {(100,500):[5,5], (100,501):[6,6], (100,502):[7,7]} >>> d.update( [[key,[x*2 for x in item]] for key,item in d.

Re: newbie question convert C to python

2005-02-15 Thread Adam DePrince
. Treat it as you would such a creature in C ... vTable[0][0] = 1 or whatever you want to do. I've seen this question before. Lot in the archives for the subject "2D array" from Dec 7th 2004 - Dec 10th 2004. Steven and I recommended roughly opposite solutions at the time :-) Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Iterator / Iteratable confusion

2005-02-15 Thread Adam DePrince
ators, reiterables, and other. I think this is > didactically useful. Spencerators are reiterables. > Iter(iterator) returning iterator unchanged makes iterator a fixed point of > iter. It ends any chain of objects returned by repeated iter calls. > Spencerators prolong any iter chain, making it infinite instead of finite. > Essential? Repeat the paragraph above with 'a fixed point' substituted for > 'minimal'. How is spencerator different than itertools.tee? Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: image fourier transform

2005-02-15 Thread Adam DePrince
gt; To do a 2D FFT on a matrix X, you do 1D FFTs on all the rows, producing X', > then you do 1D FFTs on all the columns of X'. > So, for a 32x32 2D FFT, you'll end up doing 64 1D FFTs. FFTW: http://www.fftw.org/ Python bindings for it: http://pylab.sourceforge.net/ Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-15 Thread Adam DePrince
On Tue, 2005-02-15 at 17:24, Jeff Shannon wrote: > Ilias Lazaridis wrote: > > > Adam DePrince wrote: > > [...] > >> You're on it. You drive a car? You have to treat it right to get what > >> you want, right? Same here. Ask correctly, and y

Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-15 Thread Adam DePrince
On Tue, 2005-02-15 at 14:25, Ilias Lazaridis wrote: > Adam DePrince wrote: > > On Tue, 2005-02-15 at 13:29, Ilias Lazaridis wrote: > >>Mike Meyer wrote: > >>>Ilias Lazaridis <[EMAIL PROTECTED]> writes: > [...] > >>MinGW compatibility is not [onl

Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-15 Thread Adam DePrince
empts such a feat and possibly organize unfathomable resources in the attendance of such a lofty goal. Make us proud Ilias. But whatever you do, don't beg. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Python versus Perl ?

2005-02-08 Thread Adam DePrince
> discussion). Otherwise the debate will go south real quick. Not only most speed be an issue, but the economics must be such that any alternative is better than throwing more hardware at the problem. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: pickle/marshal internal format 'life expectancy'/backward compatibility

2005-02-06 Thread Adam DePrince
e sure that the data you are reading into your python application was written by you as a hedge against malicious data. Can I, as a user of said card, change the data in the pickle? If so, when you load the pickle back into python you need to confirm that it is a sane pickle that you wrote earlier.

Re: bytecode obfuscation

2005-02-06 Thread Adam DePrince
On Sun, 2005-02-06 at 08:19, Philippe Fremy wrote: > Adam DePrince wrote: > > No amount of obfuscation is going to help you. > > Theorically, that's true. Anything obfuscated can be broken, just like > the non obfuscated version. However it takes more skills and time to

Re: pickle/marshal internal format 'life expectancy'/backward compatibility

2005-02-06 Thread Adam DePrince
file.txt", "w+" ) hash = f.read( sha.digest_size ) mydata = f.read() if sha.new( mysecret + mydata ).digest() != hash: raise "Somebody is tring to hack you!" mydata = cPickle.loads( mydata ) Of course, the security of this scheme is dependent on a lot, including the strength of sha, your ability to keep your secret key secret, the correctness of what I'm saying, etc etc etc. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: bytecode obfuscation

2005-02-06 Thread Adam DePrince
how good their implementation of your protocol. The worst case if you depend on obscurity: The bad guys are rounding off your pennies as you read this. The worse case if you depend on encryption and open your spec: You get to publish your code, but might get competition. Just my $0.02. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Trouble converting hex to decimal?

2005-02-05 Thread Adam DePrince
>>> x = '\x00' > >>> ord(x) > 0 > >>> x = '\x15' > >>> ord(x) > 21 > >>> Ethereal's emission of \x00 shouldn't make your life any more difficult. The conversion of \0xx takes place in the eval. If you store the string \x00 in a file and call open.read or command.getoutput, you will get the python string "\\x00". Stuff you read from a file arrives un-de-escaped. The solution is simple. mystring.replace( "\x","0x" ) Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I convert arithemtic string (like "2+2") to a number?

2005-02-05 Thread Adam DePrince
efarious user who might submit to you: commands.getoutput( "rm -rf %(HOME)s"%os.environ ) as the "expression" to evaluate. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing huge Sets() to disk

2005-01-10 Thread Adam DePrince
saying NP != P. Then tell us what you are tring to do; perhaps there is a better way, perhaps the problem is unsolvable and there is a heuristic that will satisfy your needs. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Download .jpg from web

2005-01-06 Thread Adam DePrince
pen so I just have to > keep read()-ing or maybe is there a type of streaming read? I have many > cameras, so there are many threads simultaneously reading and dropping them > in a central Queue for saving later. > > I appreciate it! > -Dave > > WebImage = urlli

Re: what is lambda used for in real code?

2005-01-04 Thread Adam DePrince
On Sat, 2005-01-01 at 11:42, Steve Holden wrote: > Adam DePrince wrote: > [...] > > > > In sort, we must preserve the ability to create an anonymous function > > simply because we can do so for every other object type, and functions > > are not special enou

Re: what is lambda used for in real code?

2005-01-04 Thread Adam DePrince
On Fri, 2004-12-31 at 22:09, Terry Reedy wrote: > "Adam DePrince" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > In sort, we must preserve the ability to create an anonymous function > > simply because we can do so for every other object type,

Re: what is lambda used for in real code?

2005-01-04 Thread Adam DePrince
On Fri, 2004-12-31 at 17:36, Steven Bethard wrote: > Adam DePrince wrote: > > Lets not forget the "real reason" for lambda ... the elegance of > > orthogonality. Why treat functions differently than any other object? > > > > We can operate on every othe

Re: OT: spacing of code in Google Groups

2004-12-31 Thread Adam DePrince
ling list. Take a look at http://python.org/community/lists.html The news group and this list are mirrors of each other. Of course, the benefit this provides depends on which mail client you use. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: what is lambda used for in real code?

2004-12-31 Thread Adam DePrince
e ability to create an anonymous function simply because we can do so for every other object type, and functions are not special enough to permit this special case. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Writev

2004-12-21 Thread Adam DePrince
On Sun, 2004-12-19 at 23:43, Jp Calderone wrote: > On Sun, 19 Dec 2004 23:12:27 -0500, Adam DePrince <[EMAIL PROTECTED]> wrote: > > [snip] > > > > Of course, to take advantage of this requires that writev be exposed. I > > have an implementation of writev.

Re: Writev

2004-12-20 Thread Adam DePrince
On Mon, 2004-12-20 at 02:18, Steven Bethard wrote: > Adam DePrince wrote: > > file.writelines( seq ) and map( file.write, seq ) are the same; the > > former is syntactic sugar for the later. > > Well, that's not exactly true. For one thing, map(file.write, seq) > r

Re: Writev

2004-12-19 Thread Adam DePrince
On Mon, 2004-12-20 at 00:30, Steven Bethard wrote: > Adam DePrince wrote: > > Many other programmers have faced a similar issue; cStringIO, > > ''.join([mydata]), map( file.write, [mydata]) are but some attempts at > > making this process more efficient by jamming t

Re: Writev

2004-12-19 Thread Adam DePrince
On Sun, 2004-12-19 at 23:43, Jp Calderone wrote: > On Sun, 19 Dec 2004 23:12:27 -0500, Adam DePrince <[EMAIL PROTECTED]> wrote: > > [snip] [snip] to free the memory, of course. > > The support of iterators is a cool idea, but I'm not sure > it is actually useful.

Writev

2004-12-19 Thread Adam DePrince
024 items, so to accommodate users who don't want to peel off and hold in memory 1024 iteration.next()'s, you can set an optional parameter to a smaller value. I'm not sure where to take this as a "next step." It seems too small a change for a PEP. Any ideas?

Re: Create linear spaced vector?

2004-12-17 Thread Adam DePrince
uot;__main__": print linear_space( 1.0, 2.0, 10 ) Running it gives you: [1.0, 1.1001, 1.2, 1.3, 1.3999, 1.5, 1.6001, 1.7002, 1.8, 1.8999, 2.0] Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: BASIC vs Python

2004-12-17 Thread Adam DePrince
quot;enterprise" class? The same was true 20 years ago - but it was the mere presence of the computer that served a similar role. If you were really enterprise class, you used COBOL. And if you were in the wannabe category, you got yourself a PET 20 and told it what to do in BASIC. > (mumbles into beard and drools quietly in the corner). Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: BASIC vs Python

2004-12-17 Thread Adam DePrince
wandering onto [EMAIL PROTECTED] and having strong opinions in favor of BASIC is sort of like wandering into a Hasidim temple on Yom Kippur and talking about the salvation of Jesus while munching on a ham and cheese sandwich? Don't be surprised if you have trouble making friends. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: BASIC vs Python

2004-12-17 Thread Adam DePrince
Excel in 2 > > minutes. What you describe is a political, not technical, challenge. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: BASIC vs Python

2004-12-17 Thread Adam DePrince
On Fri, 2004-12-17 at 01:49, Andrew Dalke wrote: > Adam DePrince > > During the 1980's BASIC was the language to embedd into the ROM's of the > > computers of the day. This was in a misguided effort to make computers > > understandable to their target audien

Re: os.walk bug?

2004-12-16 Thread Adam DePrince
ay of writing what you are tring to write is as follows: test.py contains: for root, dirs, files in os.walk('t:\'): if root(-4:-2) == "20": continue # Do stuff [EMAIL PROTECTED] help]$ python test.py . ./dir1 ./dir1/content ./dir2 ./dir2/content ./dir2/templates Oh, and my directory structure is ... # bash -c 'mkdir -p dir1/200{0,1} dir1/content \ dir2/200{0,1,2,3,4} dir2/{content,templates}' Does this help? - Adam > Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: BASIC vs Python

2004-12-16 Thread Adam DePrince
preted lang if it's similar to BASIC. > > > > > > > > Is a Ferrari similar to a horse-wagon? Yes, they both have 4 wheels. No, it is not better than a horse. The horse is more reliable and on any given day you can count on it going further before it needs service.

Re: lies about OOP

2004-12-16 Thread Adam DePrince
of hockey games... ;) When I read that I parsed it as reading "I'm Danish; my spouse plays a mean game of hockey." Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: BASIC vs Python

2004-12-16 Thread Adam DePrince
e word each is (scatological, sexual, religious, etc.) But you are forced to memorize the same list of curse words over and over again in order. This is the BASIC way of learning to program. Don't do it, unless your goal is simply to embarrass and insult programmers. Adam DePrince

Re: Why are tuples immutable?

2004-12-15 Thread Adam DePrince
ash value, but yours are different. A hash value is simply a probabilistic mechanism to quickly determine if two objects must be different, or to select a bin in a hash table. Two different objects are allowed to have the same hash value, but two objects that are the same must have the same

Re: lies about OOP

2004-12-15 Thread Adam DePrince
ts in the JVM, limiting the size of your procedural program masquerading as a class. Perhaps that is a good thing. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are tuples immutable?

2004-12-15 Thread Adam DePrince
lature and behavior similar to existing mathematical constructs. Doing this will afford you the opportunity to stand upon the shoulders of giants as you go about your work. And to properly stand upon those shoulders, we must match the theoretical models used. That means we need more, not fewer, immutable counterparts to most of our datatypes. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I convert characters into integers?

2004-12-15 Thread Adam DePrince
ython. You might find this weird, but ... "anystring"[0] == "anysring"[0][0][0][0][0] is always true. Taking an element returns the character as a string of length 1. Think in terms of maping here. Don't say ... for ... Think ... message = map( ord, message ) or message = [chr( (ord( x ) + 3 )%256) for x in message] Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are tuples immutable?

2004-12-15 Thread Adam DePrince
you go about your work.  And to properly stand upon those shoulders, we must match the theoetical models used.  That means we need more, not fewer, inmutable counterparts to most of our datatypes. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Python mascot proposal

2004-12-13 Thread Adam DePrince
ves. When I think of Python in emotional terms. A plush toy like Tux is more appealing. As for python2.png ... does the snake get all smushed up in the gear if it turns? Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: how do I "peek" into the next line?

2004-12-13 Thread Adam DePrince
t line, f.unreadline( line ) line = f.readline() print line, line = f.readline() print line, Running this prints: a b c c d Hope this helps. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: how do I "peek" into the next line?

2004-12-13 Thread Adam DePrince
pipes in Windows NT Pipes in Unix Comx: where x is your com port in DOS Sockets gzip and zlib file objects; this file was described as being *so* large that it should not be read into memory. IIRC seek operations are linear; while it is correct you can seek backwards, I don't think you woul

Re: newbie questions

2004-12-13 Thread Adam DePrince
both, then: def a(): something = 1 somethingelse = 2 return something,somethingelse x,y = a() This makes the code clear and easy to understand. Navré je ne pas répondre en français. - Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: lies about OOP

2004-12-13 Thread Adam DePrince
s weaknesses with respect to complexity and the ability to partition knowledge. Forget goggle. Go to Amazon and get some texts on OOPL. Learn C++, Java, Python for that matter. Practice casting problems as classes in Python and submit them here for praise and criticism. Lastly, Perl is a

Re: sources for DOS-16bit

2004-12-10 Thread Adam DePrince
K * X + Y for some unsigned 4 bit value; on the V20-V30 it was an undefined operation. What this an accident? I don't know, but a lot of assembly coders came to depend on the one or two CPU cycles it would save over a proper mul and add. One or two cycles per array reference was a big thing back then ... Anyhow, sorry about babbling on about this non-python related nonsense and good luck. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie questions

2004-12-10 Thread Adam DePrince
Now promise me that you will never, ever do this in code you consider yourself proud of. Realize I'm sharing this in the same spirit that kids in a drivers ed class might view gory accident pictures. Fortunately for you, lists are mutable. Assigning to a auto-magically makes it part of yo

Re: Deadlock detection

2004-12-10 Thread Adam DePrince
x27;t have any mutex operations. You get the idea. Unless mutex calls are rare, or your code simple, you might spend a while. Largely this problem is intractable, even with simplifications, but it is done which is why safety critical programs are (well, should be) small and their languages not

Re: 2D array

2004-12-10 Thread Adam DePrince
On Wed, 2004-12-08 at 16:22, Steven Bethard wrote: > Adam DePrince wrote: > > The use of None as the default parameter was on purpose; the lack of > > "magic" in python is often cited in religious wars between python and > > perl aficionados. Use of get(something,

Re: 2D array

2004-12-08 Thread Adam DePrince
On Wed, 2004-12-08 at 15:06, Steven Bethard wrote: > Adam DePrince wrote: > > If your data is sparse you might want to consider using a dictionary > > where the key is a tuple representing the coordinates. > > > > a = {} > > a[(0,0)] = 0 > > a[(0,1)] = 1

Re: Recursive list comprehension

2004-12-08 Thread Adam DePrince
On Wed, 2004-12-08 at 15:02, Steven Bethard wrote: > Adam DePrince wrote: > > def flatten( i ): > > try: > > i = i.__iter__() > > while 1: > > j = flatten( i.next() ) > > try: > >

Re: Sorting in huge files

2004-12-08 Thread Adam DePrince
t it up Friday night and take the weekend off. Just make sure you plug your laptop into the wall before you go home. > > Is this reasonnable to do on 10^8 elements with repeats in the keys? I > guess I should just try and see for myself. Repeats in the keys don't matter. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Recursive list comprehension

2004-12-08 Thread Adam DePrince
er(['F']) ]) def flatten( i ): try: i = i.__iter__() while 1: j = flatten( i.next() ) try: while 1: yield j.next() except StopIteration: pass except AttributeError: yield i if __n

Re: 2D array

2004-12-08 Thread Adam DePrince
der using a dictionary where the key is a tuple representing the coordinates. a = {} a[(0,0)] = 0 a[(0,1)] = 1 a[(1,0)] = 2 a[(1,1)] = 3 a[(2,0)] = 4 a[(2,1)] = 5 a[(3,0)] = 6 a[(3,1)] = 7 a[(4,0)] = 8 a[(4,1)] = 9 >>> a.get( (3,0), None ) 6 >>> print a.get( (5,0), None ) None Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: distinction between float & int

2004-12-03 Thread Adam DePrince
isting object. When strings are compiled, they are interned, so ... >>> "abc" is "abc" True >>> "abc" is ("ab" + "c") False >>> "abc" == ( "ab" + "c" ) True >>> "abc&q

Re: Newbie alert !

2004-12-03 Thread Adam DePrince
een and moves on. Would it be > correct to say that you want the program to block on the creation of > each button until it was pressed? > > Typically, GUI's rely on the notion of a callback. You create a widget, > assign some function to be called when something happens and then enter > your "mainloop" where you wait. If you want your rings to be created > with button presses then you should be creating them in the button > callbacks ... > > - Adam > > > > Using Python 2.3, IDLE and Win2k. > > > > Thanks for your time > > > > Jean Montambeault > Adam DePrince Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie alert !

2004-12-03 Thread Adam DePrince
the notion of a callback. You create a widget, assign some function to be called when something happens and then enter your "mainloop" where you wait. If you want your rings to be created with button presses then you should be creating them in the button callbacks ... - Adam > > Using Python 2.3, IDLE and Win2k. > > Thanks for your time > > Jean Montambeault Adam DePrince 973-723-8597 cell voice/tdd 973-983-7576 home voice/tdd -- http://mail.python.org/mailman/listinfo/python-list

Re: PySQLLite Speed

2004-12-02 Thread Adam DePrince
tead of data[i] > > > > > __ > Do you Yahoo!? > Yahoo! Mail - You care about security. So do we. > http://promotions.yahoo.com/new_mail Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: efficient intersection of lists with rounding

2004-12-02 Thread Adam DePrince
a] ) >>> set_b = Set( [(i,round(j)) for i,j in b] ) >>> set_a.intersection( set_b ) Set([(123, 2.0), (123, 1.0), (123, 8.0)]) Or you could say ... >>> set_a, set_b = [[Set((i,round(j))) for i,j in s] for s in (a,b )] Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list