Re: math.nroot [was Re: A brief question.]

2005-07-03 Thread Steven D'Aprano
ion is whether that's > a unary -, which binds lower than exponentiation in most systems, > or part of the negative number minus 2. In Python, all numbers are positive. -2 is a unary minus in front of 2. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: math.nroot [was Re: A brief question.]

2005-07-03 Thread Steven D'Aprano
you really telling me that you think this expression: > > 2 > -1 > > Evaluates to -1? Of course it does. That's why mathematicians use (-1)^n for series where the sign of each term alternates, instead of -1^n which would just give -1, -1, -1, ... -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-03 Thread Steven D'Aprano
to define a function to pass to map), and this > is more readable. and then, five minutes later in another post, wrote: > If you're doing heavy functional programming, > listcomps are tremendously unwieldy compared to > map et al. Having a dollar each way I see :-) -- Steven.

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-03 Thread Steven D'Aprano
Mike Meyer wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: > >>I don't object to adding sum and product to the language. I don't object >>to adding zip. I don't object to list comps. Functional, er, functions >>are a good thing. We should h

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-04 Thread Steven Bethard
Erik Max Francis wrote: > Ron Adam wrote: > >> In this case sum and product fulfill 90% (estimate of course) of >> reduces use cases. It may actually be as high as 99% for all I know. >> Or it may be less. Anyone care to try and put a real measurement on it? > > Well, reduce covers 100% of th

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-04 Thread Steven Bethard
Erik Max Francis wrote: > Steven Bethard wrote: > >> And it's almost two times slower: > > That's because you're not using operator.add. Huh? Please re-read my post. That's exactly what I used. STeVe -- http://mail.python.org/mailman/listinfo/python-list

Re: math.nroot [was Re: A brief question.]

2005-07-04 Thread Steven D'Aprano
of it, i don't > think it could do roots of imaginary numbers at all. However, python is > not a calculator. Of course it is :-) py> 1+2 3 It even works with complex numbers: py> print (-1+0j)**0.5 (6.12303176911e-17+1j) although you have to watch out for those rounding

Re: Existance of of variable

2005-07-04 Thread Steven D'Aprano
oat constructed from the string 'inf', float('inf'), may do the > trick. I don't know the details, though. > > >>> 1e100 < float('inf') > True This is not guaranteed to work in any Python. It *might* work, depending on the underlying C library, which is operating system dependent. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Steven D'Aprano
On Tue, 05 Jul 2005 05:03:32 -0700, mcherm wrote: > Steven D'Aprano writes: >> Lambda is no more an obscure name than "function", "decorator", "closure", >> "class", or "module". The first time you come across it, you don&#x

Re: Python Regular Expressions: re.sub(regex, replacement, subject)

2005-07-05 Thread Steven Bethard
Vibha Tripathi wrote: > In the Python re.sub(regex, replacement, subject) > method/function, I need the second argument > 'replacement' to be another regular expression ( not a > string) . So when I find a 'certain kind of string' in > the subject, I can replace it with 'another kind of > string' (

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Steven D'Aprano
On Tue, 05 Jul 2005 09:46:41 -0500, Terry Hancock wrote: > On Tuesday 05 July 2005 08:17 am, Steven D'Aprano wrote: >> Sorry, but you are mistaken. "lambda" is a _reserved_ word in the >> Python language, while "function" etc are not, but they are certainly

Re: math.nroot [was Re: A brief question.]

2005-07-05 Thread Steven D'Aprano
= 1 or Inf/Inf = 1. If I recall correctly, the IEEE standard requires both of those to return NaN, which is really the only correct thing to do. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Steven D'Aprano
> I hope that any student who didn't understand a word as > common as "define" wouldn't have graduated from our school. How about tuple? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Steven Bethard
Grant Edwards wrote: > [EMAIL PROTECTED] wrote: >> So I'd say that it's a pretty obscure name that most people >> wouldn't know. > > I can't believe that anybody with any computer science > background doesn't know it. Perhaps this reflects on the quality of education in the United States ;) but

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-05 Thread Steven D'Aprano
getting rid of it. I personally > might prefer keeping the feature but using a different keyword. Best of all would be if lambda was extended to allow statements, just like a real made-with-def function. Although, I worry about syntax and readability. But then I'm not completely comfortable with the existing lambda syntax either. And now, I shall say no more on this issue. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Steven D'Aprano
ge case where you didn't discover the error reasonably soon, but it would be better for leaving the iterator out of a list comp to remain a syntax error, rather than produce an unexpected, but legal, object. Besides, I think Guido should be very cautious about introducing new features that use punctuation, instead of keywords. We don't want to become perl do we? :-) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: frozenset question

2005-07-06 Thread Steven D'Aprano
works, measure how fast it runs. If, and ONLY if, it is too slow, identify the parts of the program that make it too slow. That means profiling and timing. Then optimize those parts, and nothing else. Otherwise, you will be like the car designer trying to speed up his sports cars by making the seatbelts aerodynamic. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Steven Bethard
Terry Hancock wrote: > And a syntax just occured to me -- what about this: > > [y*x for x,y] > > ? > > (that is: > > [ for ] If you haven't already, see: http://wiki.python.org/moin/AlternateLambdaSyntax for other similar proposals. STeVe -- http://mail.python.org/mailman/listinfo/python-l

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-06 Thread Steven Bethard
Ron Adam wrote: > Yes, I think a different key word would help. My current favorite > alternative is to put it in parentheses similar to list comprehensions > and use "let". > > (let x,y return x+y) If you haven't already, see: http://wiki.python.org/moin/AlternateLambdaSyntax for other simi

Deleting variables [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-06 Thread Steven D'Aprano
requires being able to delete a variable. In summary: del being a keyword works. del() being an object method is unclear, confusing and complicated. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Use cases for del

2005-07-06 Thread Steven D'Aprano
from mymodule2 import * py> a + 1 Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand type(s) for +: 'NoneType' and 'int' It is bad enough that from module import * can over-write your variables with the modules' variables, but for it to do so with DELETED variables is unforgivable. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: frozenset question

2005-07-06 Thread Steven D'Aprano
aving a thousandth of a millisecond off a program that takes five seconds to run, I'll get on with development using the right object for the functionality needed. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: frozenset question

2005-07-06 Thread Steven D'Aprano
ture optimization: don't even THINK about optimizing code until you have it WORKING and you have MEASURED that it is too slow. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Steven Bethard
Daniel Schüle wrote: > Removing lamdba would be reduce readability of Python, I think here > for examble of code like > > class App: > > > def drawLines(self, event): > from random import randint > r = lambda : randint(1, 100) > self.canvas.create_line

Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Steven D'Aprano
Steven Bethard wrote: > If you're really afraid of two lines, write it as: > > def r(): randint(1, 100) > > This is definitely a bad case for an anonymous function because it's not > anonymous! You give it a name, r. This is something I've never understo

Re: Use cases for del

2005-07-07 Thread Steven D'Aprano
ount_records(myRecords, end=myRecords.current) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: f*cking re module

2005-07-07 Thread Steven D'Aprano
l cause widespread confusion." [end quote] There is no unary = operator in Perl, yet, but Larry sees nothing wrong with the concept of syntax that confuses programmers, or of code which can be parsed as legal code by Perl even if it can't be displayed on the developer's computer. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Steven D'Aprano
On Thu, 07 Jul 2005 09:36:24 +, Duncan Booth wrote: > Steven D'Aprano wrote: >> This is something I've never understood. Why is it bad >> form to assign an "anonymous function" (an object) to a >> name? > > Because it obfuscates your code for

Re: Use cases for del

2005-07-07 Thread Steven D'Aprano
Ron Adam wrote: > Steven D'Aprano wrote: >> Er, maybe I'm misunderstanding something here, but surely the most >> obvious case is for default and special function arguments: >> >> def count_records(record_obj, start=0, end=None): >> if end == None:

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-08 Thread Steven Bethard
Christopher Subich wrote: > Ron Adam wrote: >> I think the association of (lambda) to [list_comp] is a nice >> distinction. Maybe a {dictionary_comp} would make it a complete set. ;-) > > Yeah, dictionary comprehensions would be an interesting feature. :) > Syntax might be a bit unwieldy, thoug

removing list comprehensions in Python 3.0

2005-07-08 Thread Steven Bethard
George Sakkis wrote: > "Steven Bethard" <[EMAIL PROTECTED]> wrote: >> Dict comprehensions were recently rejected: >> http://www.python.org/peps/pep-0274.html >> The reason, of course, is that dict comprehensions don't gain you >> much at

python-dev Summary for 2005-06-16 through 2005-06-30

2005-07-08 Thread Steven Bethard
[The HTML version of this Summary is available at http://www.python.org/dev/summary/2005-06-16_2005-06-30.html] = Summary Announcements = -- OSCON Registration -- Though if you haven't yet registered, you've already missed t

Re: removing list comprehensions in Python 3.0

2005-07-08 Thread Steven Bethard
Kay Schluehr wrote: > Well, I want to offer a more radical proposal: why not free squared > braces from the burden of representing lists at all? It should be > sufficient to write > list() > list() > > After being free one can use them for other purposes e.g. replacing the > ugly @ decorator

Re: removing list comprehensions in Python 3.0

2005-07-08 Thread Steven Bethard
Devan L wrote: > List comprehensions are faster than generator comprehensions for > iterating over smaller sequences. Could you give me an example? For the simple one below, the generator expression was faster: $ python -m timeit "for x in (i for i in xrange(10)): y = x" 10 loops, best of 3

Re: why UnboundLocalError?

2005-07-08 Thread Steven D'Aprano
quot;Unsupported alignment '%s'" % alignment) if not len(widths) == len(alignments) == len(fields): raise 'Argument mismatch' columns = zip(widths, alignments, fields) # builds a list of tuple of (width, alignment, field) L = [] # hold each formatted column as it is built for column in columns: L.append(align(*column)) # equivalent to: # L.append(align(column[0], column[1], column[2])) return ''.join(L) Hope this is helpful to you. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: python-dev Summary for 2005-06-16 through 2005-06-30

2005-07-08 Thread Steven Bethard
Bengt Richter wrote: > On Fri, 8 Jul 2005 18:15:37 -0600, Steven Bethard <[EMAIL PROTECTED]> wrote: > >>[The HTML version of this Summary is available at >>http://www.python.org/dev/summary/2005-06-16_2005-06-30.html] > > Not when I just looked, but maybe it takes

Re: removing list comprehensions in Python 3.0

2005-07-08 Thread Steven Bethard
Dennis Lee Bieber wrote: > On Fri, 08 Jul 2005 16:07:50 -0600, Steven Bethard > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > >>I only searched a few relatively recent threads in c.l.py, so there are >>probably more, but it looks to me like the

Re: removing list comprehensions in Python 3.0

2005-07-09 Thread Steven Bethard
Devan L wrote: import timeit t1 = timeit.Timer('list(i for i in xrange(10))') t1.timeit() > > 27.267753024476576 > t2 = timeit.Timer('[i for i in xrange(10)]') t2.timeit() > > 15.050426800054197 > t3 = timeit.Timer('list(i for i in xrange(100))') t3.timeit() > > 117

Re: removing list comprehensions in Python 3.0

2005-07-09 Thread Steven Bethard
Raymond Hettinger wrote: > The root of this discussion has been the observation that a list > comprehension can be expressed in terms of list() and a generator > expression. As George Sakkis already noted, the root of the discussion was actually the rejection of the dict comprehensions PEP. > Ho

Re: Should I use "if" or "try" (as a matter of speed)?

2005-07-09 Thread Steven D'Aprano
try: for i in range(len(L)): L[i] = 1.0/L[i] except ZeroDivisionError: pass invert(L) print L => [0.333, 0.2, 0, 2, 7, 9] - Why are you optimizing your code now anyway? Get it working the simplest way FIRST, then _time_ how long it runs. Then, if and only if it needs to be faster, should you worry about optimizing. The simplest way will often be try...except blocks. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: removing list comprehensions in Python 3.0

2005-07-09 Thread Steven Bethard
Raymond Hettinger wrote: > [Steven Bethard] > >>I would hope that in Python 3.0 list comprehensions and generator >>expressions would be able to share a large amount of implementation, and >>thus that the speed differences would be much smaller. But maybe not... > &g

Re: Should I use "if" or "try" (as a matter of speed)?

2005-07-10 Thread Steven D'Aprano
eption is no more difficult or unsafe than calling a function that returns a status flag and a result, but writing the function itself is much easier, with fewer places for the programmer to make a mistake. In effect, exceptions allow the Python programmer to concentrate on his actual program, rather than be responsible for building error-handling infrastructure into every function. Python supplies that infrastructure for you, in the form of exceptions. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: What is Expresiveness in a Computer Language?

2005-07-10 Thread Steven D'Aprano
On Sun, 10 Jul 2005 07:20:34 -0700, raptor wrote: > I think u are wrong.. I think perl is much more exrpressive in > semantics than Python.. Well, with such great command of natural language as you are displaying, how could anyone argue with your conclusion? -- Steven. --

Re: passing arguments to a function - do I need type ?

2005-07-10 Thread Steven D'Aprano
n inputVector > allDimensions[0].newAttribute(vector) > File "Memory.py", line 56, in newAttribute > dist = self.distance(n.getCenter,newElement) > File "Memory.py", line 76, in distance > dist = dist + pow((element1[n] - element2[n]),2) > TypeError: unsubscriptable object Firstly, you seem to have a lot of modules there. What happens when you call distance directly? Can you get it to work then? Secondly, what are the values for element1 and element2? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Cat and Mouse (wes Re: Efficiency of using long integers to hold bitmaps)

2005-07-11 Thread Steven D'Aprano
tanding your post than you put in writing it. As they say, be strict when sending and tolerant when receiving. I'm all for that. But when people insist on sending broken packets, I see nothing rude about bouncing those packets back with a error message or a creative misunderstanding. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: __eq__ on a dict

2005-07-11 Thread Steven D'Aprano
== dictC # calls dictB.__eq__(dictC) False Two dicts are equal if they have the same keys and the same values. In general, you should not call __eq__ directly, but use the == operator instead. Likewise: x > y becomes x.__gt__(y) x < y becomes x.__lt__(y) x >= y becomes x.__ge__(y) x <=

Re: Parsing Data, Storing into an array, Infinite Backslashes

2005-07-11 Thread Steven D'Aprano
You can't add strings to ints. > So I try and fix it by doing this: > > query[count]=`query[count]`+i[2]+"="+i[3]+", " That is functionally equivalent to your first version. > Can someone please point me in the right direction I am sure that the > `query[count]` is causing the backslashes. I doubt it very much. But you can test it by adding some print lines in your code: change this: qval=`query[count]` query[count]=qval+i[2]+"="+i[3]+", " to this: print "Count is: ", count print "query[count] is: ", query[count] qval=`query[count]` print "qval is: ", qval query[count]=qval+i[2]+"="+i[3]+", " print "query[count] changed.\nNew value is: ", query[count] -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Should I use "if" or "try" (as a matter of speed)?

2005-07-11 Thread Steven D'Aprano
eeping the disadvantages. In any case, writing masses of boilerplate code is a drain on programmer productivity, and a frequent cause of bugs. Boilerplate code should be avoided whenever you can. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: __eq__ on a dict

2005-07-11 Thread Steven D'Aprano
dictA, dictB) 1 py> cmp(dictA.items(), dictB.items()) -1 My second thought was that comparison is implemented by first comparing keys, then values, ie cmp(dictA, dictB) turns into: order = cmp(dictA.keys(), dictB.keys()) if order == 0: # keys are equal order = cmp(dictA.values(), dict

Re: __eq__ on a dict

2005-07-11 Thread Steven D'Aprano
Replying to myself... how sad. On Tue, 12 Jul 2005 15:41:46 +1000, Steven D'Aprano wrote: > That wasn't clear from his post at all. If he had explained what he > wanted, I wouldn't have wasted my time explaining what he already knew. On reading it, that came across more s

Trying to come to grips with static methods

2005-07-12 Thread Steven D'Aprano
oo) ... def bar(self): ... return 1 # just ignore the value of self ... >>> E.foo() 1 >>> e = E() >>> e.bar() 1 What are some usage cases for using Class.StaticMethod() instead of instance.method()? Everything I've read seems to just assume that t

Re: Should I use "if" or "try" (as a matter of speed)?

2005-07-12 Thread Steven D'Aprano
nt is careful encapsulation and design, so you can make significant implementation changes without needing to throw away your work. (Well, that's the theory.) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Inconsistency in hex()

2005-07-12 Thread Steven D'Aprano
also be nice if that trailing L would disappear. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: append one file to another

2005-07-12 Thread Steven D'Aprano
strictly necessary, but it is good practice. If your program dies, the files may not be closed properly and you could end up losing data. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: append one file to another

2005-07-12 Thread Steven D'Aprano
Dear me, replying to myself twice in one day... On Wed, 13 Jul 2005 00:39:14 +1000, Steven D'Aprano wrote: > Then, if you are concerned that the files really are huge, that is, as big > or bigger than the free memory your computer has, read and write them in > chunks: > > d

Re: breaking out of nested loop

2005-07-12 Thread Steven D'Aprano
we ever get here, it means we found a collision, and # flag became True, so the while loop just dropped out print "Collision!!!" stop = time.strftime("%H:%M:%S-%m-%d-%y", time.localtime()) print "Stopped at", stop -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: append one file to another

2005-07-12 Thread Steven D'Aprano
o told that Windows uses ctrl-Z as the end-of-file marker, and if it finds that character in the middle of a text file, it will assume the file has finished and stop reading. But only in text mode, not binary. I don't think that's a problem for Linux. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating anonymous functions using eval

2005-07-12 Thread Steven D'Aprano
Alternatively, if you expect a sensible answer, how about asking a sensible question? You can start by telling us just what it is that you are comparing to nested functions. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with inverted dictionary

2005-07-12 Thread Steven D'Aprano
eed to change a few things. Does this help? Is that enough to get started? See how far you get, and then come back for more help. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: removing list comprehensions in Python 3.0

2005-07-12 Thread Steven Bethard
Steven Bethard wrote: > py> def ge(items): > ... return (item for item in items if item) > ... Bengt Richter wrote: > >>> dis.dis(ge) >2 0 LOAD_CONST 1 ( expression> at 02EE4FA0, file "", line 2>) >3

Re: Creating anonymous functions using eval

2005-07-12 Thread Steven D'Aprano
y heavy hints, but that assumes the poster is capable of getting a clue. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: if not DEBUG: log = null_log

2005-07-12 Thread Steven D'Aprano
cinating. From the pyc page: "In fact you can use pyc to re-compile your standard library and make it about 100kB smaller." Hmmm. Let's see now, Python 2.3.3 on Fedora Core 2: $ du -hs /usr/lib/python2.3/ 88M /usr/lib/python2.3/ Oh joy! So by using pyc, I can save 0.11% of the Python library storage requirements! For all I know, pyc is a very useful package, and kudos to the author for taking the time and effort to develop it. But if this space saving is "one good reason to use pyc" according to the author, I'm not impressed. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: math.nroot [was Re: A brief question.]

2005-07-12 Thread Steven D'Aprano
ekend spent working solidly? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Help with inverted dictionary

2005-07-12 Thread Steven D'Aprano
y you should create 5000 or 3 text > files. There is one possible reason: if it is a homework assignment, and creating all those files is part of the assignment. (I've seen stupider ideas, but not by much.) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Building a function call?

2005-07-13 Thread Steven D'Aprano
d to maintain, and frequently a security risk. These confusing, unsafe practices can usually be avoided by remembering that functions are first class objects just like ints, strings and lists. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting on a word

2005-07-13 Thread Steven D'Aprano
[snip] > To be sure as delimiter I choose chr(127) > which surely is not present in the html file. I wouldn't bet my life on that. I've found some weird characters in HTML files. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: set and frozenset unit tests?

2005-07-13 Thread Steven Bethard
Jacob Page wrote: > Oye, there's quite a number of set and frozenset features that aren't > well-documented that I now need to implement. What a fun chore! It would be a great help if you could submit appropriate documentation patches for the areas you don't think are well-documented: http://s

Re: removing list comprehensions in Python 3.0

2005-07-13 Thread Steven Bethard
Edvard Majakari wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: > >>$ python -m timeit "for x in (i for i in xrange(10)): y = x" >>10 loops, best of 3: 4.75 usec per loop > > Yowza! One of the features I really liked in Perl has shored Python islan

Re: all possible combinations

2005-07-13 Thread Steven D'Aprano
what you need, I'm sure somebody will be able to help meet those needs. Otherwise, we're just guessing what you want. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: all possible combinations

2005-07-13 Thread Steven D'Aprano
ry. I'm looking for all 'combinations' as I > originally posted. Order does not matter to me... just all possibilities. That's good, since you only need combinations of "a", "b" and "c" the lookup table is quite small and manageable. I w

Re: all possible combinations

2005-07-13 Thread Steven D'Aprano
Notice the UNIQUE part? You should have realised that just by looking at the strings as they were printed. None of them have duplicated digits. Sampling WITHOUT replacement gives 4*3*2*1 = 24 possibilities, exactly as your code produces. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: all possible combinations

2005-07-14 Thread Steven D'Aprano
ination in the precise mathematical sense, or the common English sense? (Hint: the very first definition Google finds is "a collection of things that have been combined; an assemblage of separate parts or qualities ". Not a word there about order mattering or not.) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Inconsistency in hex()

2005-07-14 Thread Steven D'Aprano
On Wed, 13 Jul 2005 20:57:54 -0700, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> >>> hex(75) >> '0x4b' >> >>> hex(75*256**4) >> '0x4BL' >> >> By accident or design? Apart from

Re: Filtering out non-readable characters

2005-07-16 Thread Steven D'Aprano
7;'.join( ( chr(i) for i in xrange(256) ) ) with the extra spaces added for clarity. That is, the brackets after join make the function call, and the nested brackets make the generator. That, at least, is my understanding. -- Steven who is still using Python 2.3, and probably will be for quite some time -- http://mail.python.org/mailman/listinfo/python-list

Re: Filtering out non-readable characters

2005-07-16 Thread Steven D'Aprano
On Sat, 16 Jul 2005 16:42:58 -0400, Peter Hansen wrote: > Steven D'Aprano wrote: >> On Sat, 16 Jul 2005 10:25:29 -0400, Peter Hansen wrote: >>>Bengt Richter wrote: >>> >>>> >>> identity = ''.join([chr(i) for i in xrange(256)]) >

Re: Filtering out non-readable characters

2005-07-16 Thread Steven D'Aprano
I thought, oh what a nuisance that the arguments for maketrans had to include all 256 characters, then I wondered what error you would get if you left some out, and discovered that you didn't get an error at all. That actually disappointed me at the time, because I was looking for behaviour whe

Re: Filtering out non-readable characters

2005-07-16 Thread Steven D'Aprano
Replying to myself... this is getting to be a habit. On Sun, 17 Jul 2005 15:08:12 +1000, Steven D'Aprano wrote: > I hope that makes sense to you. That wasn't meant as a snide little dig at Peter, and I'm sorry if anyone reads it that way. I found myself struggling to

Tuples in function argument lists

2005-07-17 Thread Steven D'Aprano
Am I misreading the docs, or is this accidental behaviour that shouldn't be relied on? Does anyone use this behaviour, and if so, under what circumstances is it useful? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Filtering out non-readable characters

2005-07-17 Thread Steven Bethard
Bengt Richter wrote: > Thanks for the nudge. Actually, I know about generator expressions, but > at some point I must have misinterpreted some bug in my code to mean > that join in particular didn't like generator expression arguments, > and wanted lists. I suspect this is bug 905389 [1]: >>> de

Re: Efficiently Split A List of Tuples

2005-07-18 Thread Steven D'Aprano
ople trying to turn Python into Perl, by changing perfectly good, fast, readable pieces of code into obfuscated one-liners simply out of some perverse desire to optimize for the sake of optimization. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: goto

2005-07-18 Thread Steven D'Aprano
tos, not wild, dangerous ones that are out of control. You can call functions. Functions are implemented at the machine code level with the assembly language equivalent of a goto. Or you can tell us what problem you want to solve with a goto, and we'll tell you the proper way to solve it.

Re: Dictionary, keys and alias

2005-07-18 Thread Steven D'Aprano
Point the alias to the same hash as the real key. self.aliases[alias] = hash(key) def __getitem__(self, key): return self.data[self.aliases[key]] def __setitem__(self, key, value): self.data[self.aliases[key]] = value The only niggly worry I have is I'm

Re: goto

2005-07-18 Thread Steven Bethard
Hayri ERDENER wrote: > what is the equivalent of C languages' goto statement in python? Download the goto module: http://www.entrian.com/goto/ And you can use goto to your heart's content. And to the horror of all your friends/coworkers. ;) STeVe -- http://mail.python.org/mailman/listinfo

Re: goto

2005-07-18 Thread Steven Bethard
rbt wrote: > Steven Bethard wrote: > >>Download the goto module: >> http://www.entrian.com/goto/ >>And you can use goto to your heart's content. And to the horror of all >>your friends/coworkers. ;) > > Shouldn't that be "to the horror of

Re: goto

2005-07-18 Thread Steven D'Aprano
se any software that wasn't written using goto. So I'm going to buy a Windows machine. Do you recommend any anti-virus and anti-spyware software that's easy to use?" -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: goto

2005-07-18 Thread Steven Bethard
Fernando Perez wrote: > Steven Bethard wrote: > >>Download the goto module: >> http://www.entrian.com/goto/ >>And you can use goto to your heart's content. And to the horror of all >>your friends/coworkers. ;) > > That is actually a _really_ cool p

Re: goto

2005-07-19 Thread Steven D'Aprano
0 compared COMEFROM 8 11 comefrom COMEFROM 5 12 usingCOMEFROM 1 -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionary, keys and alias

2005-07-19 Thread Steven D'Aprano
one. This is guaranteed to be unique, no matter what. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Filtering out non-readable characters

2005-07-19 Thread Steven D'Aprano
nload application 19 Run installer 20 Reboot 21 Run EdXor 22 Open file 23 Select all 24 Select Format>Wipe Non-ASCII 25 Select Save 26 Quit EdXor Hmmm. Perhaps not *quite* the easiest way :-) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Could anyone write a small program to log the Signal-to-Noise figures for a Netgear DG834 router?

2005-07-19 Thread Steven D'Aprano
roject to work on out of love? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: goto

2005-07-19 Thread Steven D'Aprano
the cards are in sorted order." Bogosort is nothing to be proud of, except as a joke. Put it this way: of all the many ways to generate a list of permutations, you managed to find perhaps the least efficient algorithm possible. This is especially ironic when you think back to your first ques

Re: popen2 usage

2005-07-19 Thread Steven Bethard
jb wrote: > Hi there: > > I need help with popen2 usage. I am coding on Windows 2000 environment > and I am basically trying to run command line executable program that > accepts command line arguments from user. I want to be able to provide > these arguments through input pipe so that executable

Re: is this pythonic?

2005-07-21 Thread Steven D'Aprano
h encapsulation is just as bad as too little. > def my_enumerate(enumerable): > i = 0 > for elt in enumerable: > yield (i, elt) > i += 1 > > for i, url in my_enumerate(links): > > but it's not too bad as it is. Also, my function is completely >

Hash functions

2005-07-21 Thread Steven D'Aprano
Do people often use hash() on built-in types? What do you find it useful for? How about on custom classes? Can anyone give me some good tips or hints for writing and using hash functions in Python? Thank you, -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: is this pythonic?

2005-07-21 Thread Steven D'Aprano
don't have any > objections to it being asked here. > > If people were to ask what the function signature for enumerate() was > when that is easy to Google, then I would think they were wasting > everyone's time. And on that, I think we can agree! -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: is this pythonic?

2005-07-21 Thread Steven D'Aprano
ing about Usenet and the Internet is that we can pick each other's brains for answers, instead of flailing around blindly in manuals that don't understand the simplest natural language query. And isn't that why we're here? Regards, -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Apology [was: is this pythonic]

2005-07-21 Thread Steven D'Aprano
's not a bad thing.) My apologies to Bill specifically, and [shameless brown-nosing here] thank you to the comp.lang.python community, which as a whole is far more tolerent than many other forums I've been on. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Difference between " and '

2005-07-21 Thread Steven D'Aprano
ut there it is. One wouldn't, I hope, misunderstand "What is the difference between spaghetti marinara and spaghetti pescatora?" and attempt to subtract one from the other, since subtraction is not defined for foodstuffs. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Difference between " and '

2005-07-23 Thread Steven D'Aprano
On Fri, 22 Jul 2005 08:38:28 -0400, Peter Hansen wrote: > Steven D'Aprano wrote: >> It may shock some people to learn that difference in the sense of >> mathematical subtraction is not the only meaning of the word, but there >> it is. One wouldn't, I hope, misund

Re: tuple to string?

2005-07-23 Thread Steven D'Aprano
0x6D): L.append(chr(n)) print ''.join(L) or even: >>> ''.join(map(lambda n: chr(n), (0x73, 0x70, 0x61, 0x6D))) 'spam' -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

<    41   42   43   44   45   46   47   48   49   50   >