pre-PEP: Print Without Intervening Space

2005-03-11 Thread Marcin Ciura
Here is a pre-PEP about print that I wrote recently. Please let me know what is the community's opinion on it. Cheers, Marcin PEP: XXX Title: Print Without Intervening Space Version: $Revision: 0.0 $ Author: Marcin Ciura Status: Draft Type: Standards Track Created: 11-Mar-2005 Post-Histor

Re: pre-PEP: Print Without Intervening Space

2005-03-11 Thread Marcin Ciura
Duncan Booth wrote: import sys def nospace(value, stream=None): '''Suppress output of space before printing value''' stream = stream or sys.stdout stream.softspace = 0 return str(value) I'm teaching Python as the first programming language to non-computer scientists. Many of the toy

Re: pre-PEP: Print Without Intervening Space

2005-03-11 Thread Marcin Ciura
Larry Bates wrote: I fail to see why your proposed solution of: for x in seq: print fn(x),, print is clearer than: print ''.join([fn(x) for x in seq]) Thank you for your input. The latter form is fine with me personally, but you just can't explain it to complete novices. My prop

Re: pre-PEP: Print Without Intervening Space

2005-03-11 Thread Marcin Ciura
In view of Duncan's response, which invalidates the premises of my proposal, I announce the end of its short life. I will add Duncan's solution to my bag of tricks - thank you! Marcin -- http://mail.python.org/mailman/listinfo/python-list

Re: pre-PEP: Print Without Intervening Space

2005-03-12 Thread Marcin Ciura
Steve Holden wrote: You could think about teaching them the linelist.append(fn(x)) way, which then gives you the choice of "".join(linelist) - no gaps "\n".join(lienlist) - one item per line " ".join(linelist) - spaces between items. Sure I will. Next week, when we come to list operations. .

Re: pre-PEP: Print Without Intervening Space

2005-03-12 Thread Marcin Ciura
Bengt Richter wrote: BTW, what makes you think any self-respecting "scientist" wouldn't be insulted by the idea of your spoon-feeding them a dumbed-down programming equivalent of "See Spot run"? Am I right thinking that your dream 3 R's curriculum starts with "Stately, plump Buck Mulligan" and Póly

Re: Large Dictionaries

2006-06-09 Thread Marcin Ciura
Tim Peters wrote: > shellsort is much more a refinement of insertion-sort than of > bubblesort, but is not an O(N log N) algorithm regardlesss. With a judiciously chosen increment sequence, the number of comparisons made by shellsort *is* of the order N log N for practical values of N. See Figure

Re: Large Dictionaries

2006-06-09 Thread Marcin Ciura
Duncan Booth wrote: > Marcin Ciura wrote: >>See Figure 8 in >>http://sun.iinf.polsl.gliwice.pl/~mciura/shellsort.pdf > That isn't what the reference says. It only covers N up to a few thousand. > Practical values of N need to at least go up into the millions. Please loo

Re: Accessing variable from a function within a function

2007-06-24 Thread Marcin Ciura
Nathan Harmston wrote: > Unfortunately this doesnt work since a,a1,b,b1 arent declared in the > function. Is there a way to make these variables accessible to the > euclid function. Or is there a better way to design this function? The canonical recommendations are: use attributes of the inner fun

Python 3000 idea: reversing the order of chained assignments

2007-03-21 Thread Marcin Ciura
Given class Node(object): pass node = Node() nextnode = Node() I tried to refactor the following piece of code node.next = nextnode node = nextnode as node = node.next = nextnode only to discover that Python performs chained assignments backwards compared to other langu

Re: Python 3000 idea: reversing the order of chained assignments

2007-03-21 Thread Marcin Ciura
Steven D'Aprano wrote: x, y, z = 1, 2, 3 x = y = z x, y, z > > (3, 3, 3) > > I certainly wouldn't expect to get (2, 3, 3). Neither would I. I must have expressed myself not clearly enough. Currently x = y = z is roughly equivalent to x = z y = z I propose to change it to y = z x = z

Gosper arithmetic in Python

2007-02-12 Thread Marcin Ciura
Hello, I hacked together a module implementing exact real arithmetic via lazily evaluated continued fractions. You can download it from http://www-zo.iinf.polsl.gliwice.pl/~mciura/software/cf.py an use as an almost drop-in replacement for the math module if you don't care too much about performanc

Re: finding out the precision of floats

2007-02-28 Thread Marcin Ciura
Arnaud Delobelle wrote: > I'm not doing 'real world' calcultations, I'm making an app to help > teach children maths. I need numerical values that behave well as > decimals. I also need them to have an arbitrary number of significant > figures. Floats are great but they won't help me with either.

Re: any() and all() on empty list?

2006-03-30 Thread Marcin Ciura
Georg Brandl wrote: > Steven D'Aprano wrote: >>all(flying elephants which are pink) => true >>all(flying elephants which are not pink) => true >> >>So, these flying elephants -- are they pink or not? > > No, you ask two different sets whether they are true. No, there is only one empty set. Releva