Re: Parsing text

2005-12-20 Thread Bengt Richter
[15:22] C:\pywk\clppy24 extractfilesegs.py -tf xd ^(irrelevant) Files created: xd\irrelevant.txt xd\irrelevant.txt irrelevant trailing stuff ... HTH, NO WARRANTIES ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: how to remove duplicated elements in a list?

2005-12-19 Thread Bengt Richter
the order ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Can you pass functions as arguments?

2005-12-19 Thread Bengt Richter
... sum100(square) 338350 or if the OP actually wants the specific function, def sum100a(f): return sum(imap(f, xrange(101))) ... sum100a(square) 338350 Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Next floating point number

2005-12-18 Thread Bengt Richter
On Sun, 18 Dec 2005 10:27:16 +1100, Steven D'Aprano [EMAIL PROTECTED] wrote: On Sat, 17 Dec 2005 09:26:39 +, Bengt Richter wrote: I wonder if this won't work (for IEEE 754 double that is) ^^^[1] from math import frexp def nextf(x, y

Re: Accessing next/prev element while for looping

2005-12-18 Thread Bengt Richter
) ... 'NULL' 0 1 0 1 2 1 2 3 2 3 'NULL' If you want to assign back into myarray[i-1] etc, you'd still need to enumerate, but you could combine with the above it was useful. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo

Re: Next floating point number

2005-12-17 Thread Bengt Richter
wonder if this won't work (for IEEE 754 double that is) from math import frexp def nextf(x, y): f,e = frexp(x) if (f==0.5 or f==-0.5) and x=y: eps = 2.0**-54 else: eps = 2.0**-53 if xy: return (f+eps)*2.0**e else: return (f-eps)*2.0**e Regards, Bengt Richter -- http

Re: Problem with Lexical Scope

2005-12-17 Thread Bengt Richter
wrote, which optimizes global accesses and other stuff. No warranties, mind! ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with Lexical Scope

2005-12-16 Thread Bengt Richter
. There are always security issues in exec-ing or eval-ing, so I am not recommending the above as secure from malicious rule-writers, obviously. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with Lexical Scope

2005-12-16 Thread Bengt Richter
' etc ... Seem like it would be fairly easy to translate to code in a function per rule group, without any fancy parsing. I don't like XML that much, but that might be a possible representation too. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: access to preallocated block of memory?

2005-12-15 Thread Bengt Richter
more clearly to us what the problem is. What modules/libraries do you have to give you access now from python to the vxworks environment? A file system? /dev/magic_stuff? or /proc/magic_stuff or ? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Overlapping Regular Expression Matches With findall()

2005-12-15 Thread Bengt Richter
(0) for m in rxo.finditer(s)) if w not in seen and not seen.add(w)] ['cate', 'cat', 'cater'] BTW, note to put longer ambiguous match first in re, e.g., not r'cat(?:e|er)?') for above. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Still Loving Python

2005-12-14 Thread Bengt Richter
think you would if you'd spent enough time to get fluent in it. (I don't know what the current state of Delphi is though. I'm speaking from experience mostly with the ancient Delphi3 whose output you see above ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Still Loving Python

2005-12-14 Thread Bengt Richter
On Wed, 14 Dec 2005 10:07:04 -0500, Mike Meyer [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] (Bengt Richter) writes: A single click compiles, links and runs the resulting independent windows .exe in a fraction of a second for the above, and I can see the hint, kill the .exe, and go on where I

Re: ?: in Python

2005-12-14 Thread Bengt Richter
evaluates the expression in one branch, as with C ternary. You're right, there is a PEP and a ternary expression coming to python though. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: to write set of values to a file from python

2005-12-14 Thread Bengt Richter
([.1]) 0.1 .1 0.10001 Apparently it's str, not repr being used, so you may want to convert to string representation yourself, according to need. See also help(csv) for other options. HTH Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie: generate a function based on an expression

2005-12-13 Thread Bengt Richter
, you could substitute them as literal values in the expression before generating the function. You could do that in the placeholder vetexpr, but we'll leave that implementation for another post ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: slice notation as values?

2005-12-12 Thread Bengt Richter
, 'v') (24, 'y') for el in enoomerate[lst, 3]: print el, ... (0, 'a') (1, 'b') (2, 'c') for el in enoomerate[lst, 3:6]: print el, ... (3, 'd') (4, 'e') (5, 'f') for el in enoomerate[lst, 3:6:2]: print el, ... (3, 'd') (5, 'f') Regards, Bengt Richter -- http://mail.python.org/mailman

Re: lambda (and reduce) are valuable

2005-12-12 Thread Bengt Richter
, 3-d//3) for d in xrange(9)): Button(label=label, command=lambda d=int(label):user_pressed(d)).grid(column=x, row=y) or for tup in ((str(d+1), d%3+1,3-d//3) for d in xrange(9)): digit(*tup) tweak 'til correct ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo

Re: Problem with Lexical Scope

2005-12-12 Thread Bengt Richter
_(): rebind('initval', initval+incr) # vs initval := initval+incr return initval return _ bump3 = mkbumper(8, 3) bump3() = 11 bump3() = 14 I wonder if a function would fly better than a punctuation tweak on bare name assignment ;-) Regards, Bengt Richter

Re: Problem with Lexical Scope

2005-12-12 Thread Bengt Richter
the lines? ;-) (Of course you might want to log stuff instead of blowing up on the first assert.) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal: Inline Import

2005-12-11 Thread Bengt Richter
On Sat, 10 Dec 2005 19:40:08 -0800, Robert Kern [EMAIL PROTECTED] wrote: Bengt Richter wrote: Are you willing to type a one-letter prefix to your .re ? E.g., class I(object): ... def __getattr__(self, attr): ... return __import__(attr) [snip] There are special caveats re

Re: Random Number Generation?

2005-12-11 Thread Bengt Richter
this playing, what was it you actually wanted? ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: OO in Python? ^^

2005-12-11 Thread Bengt Richter
;-) ,@ °º¤øø¤º°`°º¤øø¤º°P`°º¤ø,,y,,ø¤º°t`°º¤ø,,h,,ø¤º°o`°º¤ø,,n,,ø¤º° Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: slice notation as values?

2005-12-10 Thread Bengt Richter
intermediately, lst = ['ham','eggs','bacon','spam','foo','bar','baz'] import itertools list(itertools.islice(enumerate(lst), 0, None, 2)) [(0, 'ham'), (2, 'bacon'), (4, 'foo'), (6, 'baz')] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal: Inline Import

2005-12-10 Thread Bengt Richter
in threads, but otherwise I don't know of any significant downsides to importing at various points of need in the code. The actual import is only done the first time, so it's effectively just a lookup in sys.modules from there on. Am I missing something? Regards, Bengt Richter -- http://mail.python.org

Re: efficient 'tail' implementation

2005-12-09 Thread Bengt Richter
unix endings, and I didn't download it in a manner that would convert it. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Calculating Elapsed Time

2005-12-07 Thread Bengt Richter
,(-float.__sub__(t(),t()) for x in xrange(1))))**-1 100.9536752259 min(filter(None,(-float.__sub__(c(),c()) for x in xrange(1))))**-1 149147.75106031806 Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Calculating Elapsed Time

2005-12-07 Thread Bengt Richter
the module would refuse to load if there wasn't a suitable chip, IIRC). Sigh. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Documentation suggestions

2005-12-07 Thread Bengt Richter
the Beginner's Guide link. (it's gotten nicer, so maybe I'll snag me a fresh offline-usable copy, and update my StartHelp menu ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: i=2; lst=[i**=2 while i1000]

2005-12-06 Thread Bengt Richter
) or b[0]1000 and b.pop(0) or None, None)) [2, 4, 16, 256] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: i=2; lst=[i**=2 while i1000]

2005-12-06 Thread Bengt Richter
(i) ... lst [4, 16, 256, 65536] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Calculating Elapsed Time

2005-12-06 Thread Bengt Richter
help(time) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Binary representation of floating point numbers

2005-12-06 Thread Bengt Richter
('1011', 2)) eval(repr(bv11)) == bv11 True import sys Bitview(sys.maxint) Bitview(int('0111', 2)) Add niceties to taste ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: str attributes

2005-12-06 Thread Bengt Richter
in the seach slot. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: what's wrong with lambda x : print x/60,x%60

2005-12-05 Thread Bengt Richter
produced no callable from:\n%s'%src) ... f = dumbda(def foo(x): print 'foo(%r)'%x) f('hello foo') foo('hello foo') I'd prefer an anonymous def though ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Bitching about the documentation...

2005-12-05 Thread Bengt Richter
with something like [BeginPythonDocsHarvest] LinkToThisThread: http://docs.python.org/about.html [EndPythonDocsHarvest] I guess I better stop ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Memoizing decorator

2005-12-05 Thread Bengt Richter
= inst ... return self ... FunMethod.__call__ = __call__ # to get access to f _cache ... return FunMethod() ... test_memoize(memoize_FM) fn (eval 1) 1 fn 1 meth (eval 1) 1 meth 1 Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Iterating over test data in unit tests

2005-12-05 Thread Bengt Richter
://codespeak.net/py/current/doc/test.html#generative-tests-yielding-more-tests Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Most SHAMEFUL one-liner:

2005-12-04 Thread Bengt Richter
on to do: .join(fill) Talk about using the wrong tool for the job... :( All I needed was: * (columns - 1) * (yoffset - 2) So the original was wrong as well as a bit opaque? (What happened to the \n ? ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: advice : how do you iterate with an acc ?

2005-12-03 Thread Bengt Richter
On 2 Dec 2005 18:34:12 -0800, [EMAIL PROTECTED] wrote: Bengt Richter wrote: It looks to me like itertools.groupby could get you close to what you want, e.g., (untested) Ah, groupby. The generic string.split() equivalent. But the doc said the input needs to be sorted. seq = [3,1,4,'t

Re: os.rename copies when old is in-use - is this deliberate?

2005-12-03 Thread Bengt Richter
: rename(...) rename(old, new) Rename a file or directory. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: advice : how do you iterate with an acc ?

2005-12-03 Thread Bengt Richter
On 3 Dec 2005 03:28:19 -0800, [EMAIL PROTECTED] wrote: Bengt Richter wrote: On 2 Dec 2005 18:34:12 -0800, [EMAIL PROTECTED] wrote: Bengt Richter wrote: It looks to me like itertools.groupby could get you close to what you want, e.g., (untested) Ah, groupby. The generic string.split

Re: Checking length of each argument - seems like I'm fighting Python

2005-12-03 Thread Bengt Richter
try to quack like the ducks you need, if possible and safe. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to execute an EXE via os.system() with spaces in the directory name?

2005-12-03 Thread Bengt Richter
@echo %* and substitute echoargs (with path if necessary) in place of your executable in CMD2? Just suggestions to get more symptoms for diagnosis. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: [[x,f(x)] for x in list that maximizes f(x)] --newbie help

2005-12-02 Thread Bengt Richter
((f(x),x) for x in mylist) (10, 5) Ok, be picky ;-) pair = list(reversed(max((f(x),x) for x in mylist))) pair [5, 10] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Death to tuples!

2005-12-02 Thread Bengt Richter
On 2 Dec 2005 13:05:43 GMT, Antoon Pardon [EMAIL PROTECTED] wrote: On 2005-12-02, Bengt Richter [EMAIL PROTECTED] wrote: On 1 Dec 2005 09:24:30 GMT, Antoon Pardon [EMAIL PROTECTED] wrote: On 2005-11-30, Duncan Booth [EMAIL PROTECTED] wrote: Antoon Pardon wrote: Personnaly I expect

Re: advice : how do you iterate with an acc ?

2005-12-02 Thread Bengt Richter
accept an iterator instead of a list. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-12-01 Thread Bengt Richter
of a test and a text file with the choices (which are one-line sources that get written to test_... so the test can do from test_... import CandidateDict and have the chosen class by the name it uses for both. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-12-01 Thread Bengt Richter
? 3) how often updated? 3a) just ordering, no value or size change? 3b) just value change, no order or size change? 3c) changes involving size? 4) proportions of read vs write/delete/reorder accesses? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Death to tuples!

2005-12-01 Thread Bengt Richter
=NotImplemented) if arg is NotImplemented: arg = [] maybe SENTINEL could be defined similarly as a builtin constant. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: Dao Language v.0.9.6-beta is release!

2005-12-01 Thread Bengt Richter
On Wed, 30 Nov 2005 20:53:50 -0500, [EMAIL PROTECTED] wrote: Please trim replies... ; ) Not quite so far ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: New Ordered Dictionery to Criticise

2005-12-01 Thread Bengt Richter
as d.items()[sliceinst]. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Nested loop

2005-11-30 Thread Bengt Richter
: priceNew.write(showme[3]+ +showme[10]) It would probably be more robust to check for blank lines and showme missing fields and symbol duplicates also. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: How to list currently defined classes, methods etc

2005-11-30 Thread Bengt Richter
On Wed, 30 Nov 2005 20:55:46 -0500, Peter Hansen [EMAIL PROTECTED] wrote: Deep wrote: If i start a python shell. Is there a way to list the currently defined classes, methods, variables? Does this work? dir() help(__name__) might be interesting for the OP too ;-) Regards, Bengt

Re: Death to tuples!

2005-11-29 Thread Bengt Richter
in place of a dict for e.g. '%(name)s'% {'name':'name value'} Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Death to tuples!

2005-11-29 Thread Bengt Richter
.__classvars__ somethow as if that were an overriding front end base class dict of the mro chain. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Precision for equality of two floats?

2005-11-29 Thread Bengt Richter
problem for optimizers generating machine code? Or is it spec-ed for mandatory as-if-storing-both-arguments-as-double-before-comparing behaviour? Just wondering ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: General question about Python design goals

2005-11-29 Thread Bengt Richter
On Tue, 29 Nov 2005 00:52:25 -0500, Mike Meyer [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] (Bengt Richter) writes: Then feel free to submit patches for the docs. This is easy to say, and maybe the docs maintainers are accomodating, but I'd be the average reader wouldn't have a concept of how

Re: General question about Python design goals

2005-11-29 Thread Bengt Richter
better, if someone had thought of it. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Death to tuples!

2005-11-29 Thread Bengt Richter
On Tue, 29 Nov 2005 09:26:53 -0600, [EMAIL PROTECTED] wrote: --cvVnyQ+4j833TQvp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Nov 29, 2005 at 10:41:13AM +, Bengt Richter wrote: Seems like str.__mod__ could take an arbitary (BTW, matching length

Re: Why are there no ordered dictionaries?

2005-11-29 Thread Bengt Richter
On Sun, 27 Nov 2005 12:00:23 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: Bengt Richter wrote: d.keys[:] = newkeyseq Do you really mean just re-ordering the keys without a corresponding reording of values?? That would be a weird renaming of all values. Or do you means that any key

Re: Why are there no ordered dictionaries?

2005-11-29 Thread Bengt Richter
-track for me ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Computer Language Shootout

2005-11-29 Thread Bengt Richter
into yours below parts of yours the put relevant response below what it is responding to) all belong down here. Double-pfui. I better eat. I note that I was a bit too easily provoked into this grumpiness ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Computer Language Shootout

2005-11-29 Thread Bengt Richter
On 29 Nov 2005 18:34:34 -0800, [EMAIL PROTECTED] wrote: Bengt Richter wrote: On 29 Nov 2005 14:08:12 -0800, [EMAIL PROTECTED] wrote: We don't scrape programs from news-groups, if you'd like the program to be shown on the shootout then please attach the source code to a tracker item. You

Re: newbie question concerning formatted output

2005-11-29 Thread Bengt Richter
... ... 3707 ... 5a07 ... ... )) import itertools for k,g in itertools.groupby(ins, lambda _, c=itertools.count().next: c()//3): ... print '%s %s %s' % tuple(g) ... 3905 3009 4508 f504 3707 5a07 Regards, Bengt Richter -- http://mail.python.org/mailman

Re: newbie question concerning formatted output

2005-11-29 Thread Bengt Richter
('xyplan.nobreaks'))] for z in (zip(it, it, it) )) 3905 3009 4508 f504 3707 5a07 Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: General question about Python design goals

2005-11-28 Thread Bengt Richter
submissions)? That's wiki-like, but I'm thinking a tailored utility. Given reasonably structured doc sources, I wouldn't think it would be too bad a project. Not that I'm volunteering to write that particular thing ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-26 Thread Bengt Richter
On Thu, 24 Nov 2005 18:42:45 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: Bengt Richter schrieb: d.setvalues((13, 14)) == d = OrderedDict((1, 13), (2, 14)) The implication above is that OrderedDict takes an *args argument, but really it takes a single argument that is a sequence of k

Re: Why are there no ordered dictionaries?

2005-11-26 Thread Bengt Richter
On Fri, 25 Nov 2005 19:42:49 +, Tom Anderson [EMAIL PROTECTED] wrote: On Wed, 23 Nov 2005, Carsten Haese wrote: On Wed, 2005-11-23 at 15:17, Christoph Zwerschke wrote: Bengt Richter wrote: E.g., it might be nice to have a mode that assumes d[key] is d.items()[k][1] when key

Re: Whitespace test after string.split

2005-11-26 Thread Bengt Richter
', 'delta'] As a second question, I am seeing string split as deprecated in 2.4.2 manual. What is planned in future to split (strings or unicode)? Just use the corresponding methods, e. g. s.strip() instead of string.strip(s) etc. Peter Regards, Bengt Richter -- http://mail.python.org

Re: Converting a flat list to a list of tuples

2005-11-24 Thread Bengt Richter
On Wed, 23 Nov 2005 13:23:21 +0100, Fredrik Lundh [EMAIL PROTECTED] wrote: Bengt Richter wrote: Are you thinking of something like lines from a file, where there might be chunky buffering? ISTM that wouldn't matter if the same next method was called. Here we have multiple references

Re: strange behaviour when writing a large amount of data on stdout

2005-11-24 Thread Bengt Richter
\Common Files\Microsoft Shared\MSInfo\MSINFO32.exe on my system. Since it's accessible from Word, I wouldn't think it would be too unsafe to run, but I guess the OP might not want to start diagnostic things on arbitrary devices etc., if that's accessible from his session. Regards, Bengt Richter -- http

Re: defining the behavior of zip(it, it) (WAS: Converting a flatlist...)

2005-11-24 Thread Bengt Richter
On Wed, 23 Nov 2005 17:55:35 +0100, Fredrik Lundh [EMAIL PROTECTED] wrote: so how equivalent must something be to be equivalent? quack, quack? ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-24 Thread Bengt Richter
subclassing list in a constrained way instead of dict, but well see. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: strange behaviour when writing a large amount of data on stdout

2005-11-24 Thread Bengt Richter
On 24 Nov 2005 03:22:26 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Bengt Richter wrote: If windows has been running a long time (a few days or a week may be long ;-) it may get fragmented in some smallish memory arena reserved for special things (I forgot what versions, but I

Re: Python as Guido Intended

2005-11-24 Thread Bengt Richter
he's made over many years. Where my first impulse is to think that one of decisions is wrong, nine times out of ten in time I'll come to find that I was wrong and he was right. You have a reservation about that other 10% ? ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo

Re: sort in the list

2005-11-23 Thread Bengt Richter
of 1j 1j Traceback (most recent call last): File stdin, line 1, in ? TypeError: cannot compare complex numbers using , =, , = (1j,) (1j,) False Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Anyway to clarify this code? (dictionaries)

2005-11-23 Thread Bengt Richter
On 22 Nov 2005 19:52:40 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Bengt Richter wrote: def my_search(another, keys, x): return dict((k,another[k]) for k in keys if another[k]x) ... my_search(another, 'cb', .3) {'b': 0.35806602909756235} my_search(another, 'abcd', .4

Re: Why are there no ordered dictionaries?

2005-11-23 Thread Bengt Richter
where the use case is just string dict keys. But feature creep is sure a threat to clean design. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a flat list to a list of tuples

2005-11-23 Thread Bengt Richter
On Wed, 23 Nov 2005 09:54:46 +0100, Fredrik Lundh [EMAIL PROTECTED] wrote: Bengt Richter wrote: Though it looks nice, it's an implementation dependant solution. What if someone changes zip to fetch the second item first? That would be a counter-intuitive thing to do. Most things go left

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On Tue, 22 Nov 2005 10:06:07 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: Bengt Richter schrieb: Ok, so if not in the standard library, what is the problem? Can't find what you want with google and PyPI etc.? Or haven't really settled on what your _requirements_ are? That seems

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On 22 Nov 2005 03:07:47 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Bengt Richter wrote: Ok, so if not in the standard library, what is the problem? Can't find what you want with google and PyPI etc.? Or haven't really settled on what your _requirements_ are? That seems

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On Tue, 22 Nov 2005 10:26:22 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: Bengt Richter wrote: d = OrderedDict(); d[1]='one'; d[2]='two' = list(d) = [1, 2] ok, now we do d[1]='ein' and what is the order? list(d) = [2, 1] ?? Or do replacements not count as insertions? If you simply

Re: Converting a flat list to a list of tuples

2005-11-22 Thread Bengt Richter
in the subject rather than the question in the body: aList = ['a', 1, 'b', 2, 'c', 3] it = iter(aList) zip(it, it) [('a', 1), ('b', 2), ('c', 3)] Thank you for that. That is cool ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a flat list to a list of tuples

2005-11-22 Thread Bengt Richter
of this before, but I can't think of the context off hand. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a flat list to a list of tuples

2005-11-22 Thread Bengt Richter
if someone changes zip to fetch the second item first? That would be a counter-intuitive thing to do. Most things go left-right in order as the default assumption. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for magic method to override to prevent dict(d) from grabbing subclass inst d contents directly

2005-11-22 Thread Bengt Richter
On Tue, 22 Nov 2005 09:30:49 -0500, Mike Meyer [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] (Bengt Richter) writes: Has anyone found a way besides not deriving from dict? Shouldn't there be a way? TIA (need this for what I hope is an improvement on the Larosa/Foord OrderedDict ;-) I guess I

Re: Converting a flat list to a list of tuples

2005-11-22 Thread Bengt Richter
, 2)] zip(range(4), range(3)) [ (0, 0), (1, 1), (2, 2)] (I just hacked this out, so maybe it's not bullet-proof, but the point is, I think there's no reason not to define the behaviour of zip to cycle through its arguments in the intuitive way). Regards, Bengt Richter -- http://mail.python.org

Re: Converting a flat list to a list of tuples

2005-11-22 Thread Bengt Richter
, 'b'), (2, 'c', 3)] [tuple(g) for _, g in groupby(aList, grouper(4))] [('a', 1, 'b', 2), ('c', 3)] Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
concat if none matched, and variations mixing both ways. But with the current version you can already write that as OrderedDict(d1.items()[0:1]+d2.items()[2:3]) you just want the sugar? d1+d2 would be like using [:] in the above line Not a biggie to do. Regards, Bengt Richter -- http

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
the OrderedDict constructor. Ditto for ordered dicts, since they give your their ordered items with the items() method as a start. I guess one could pass a key=fun keyword arg to the OrderedDict constuctor to imply a pre-construction sort. Regards, Bengt Richter -- http://mail.python.org/mailman

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
On 22 Nov 2005 11:18:19 -0800, Kay Schluehr [EMAIL PROTECTED] wrote: Bengt Richter wrote: On Mon, 21 Nov 2005 01:27:22 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: Note that is isn't hard to snap a few pieces together to make an ordered dict to your own specs. But IMO it belongs

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
, 14), (2, 12), (1, 11)] d1.keys() [3, 4, 2, 1] d1.values() [13, 14, 12, 11] d1[1:2] {4: 14} d1[-1:] {1: 11} Que mas? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
, then later duplicate keys just replace prior ones by same rules as d[k]=v1; d[k]=v2. I think that makes sense in this context, and can be defined unambigously. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a flat list to a list of tuples

2005-11-22 Thread Bengt Richter
On 22 Nov 2005 16:32:25 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Bengt Richter wrote: On 22 Nov 2005 07:42:31 -0800, George Sakkis [EMAIL PROTECTED] wrote: Laurent Rahuel wrote: Hi, newList = zip(aList[::2], aList[1::2]) newList [('a', 1), ('b', 2), ('c', 3)] Regards

Re: Anyway to clarify this code? (dictionaries)

2005-11-22 Thread Bengt Richter
': 0.77440643221840166} This sounds like homework though ... ? Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-22 Thread Bengt Richter
be the result of arbitrary permutation, e.g., manual shuffling, etc. Of course either way, a result can be said to have a particular defined order, but sorted gets ordered by sorting, and ordered _may_ get its order by any means. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python

Re: need help about time.sleep, timer

2005-11-21 Thread Bengt Richter
down ;-) HTH (once I get it posted -- news reads ok now but news server is not accepting posts. I suspect they do system-hogging chores Sun night wee hours ;-/ Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Command line

2005-11-21 Thread Bengt Richter
delayed 12 hrs due to news server prob ;-/ ) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-21 Thread Bengt Richter
On 20 Nov 2005 21:12:52 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Bengt Richter wrote: On Sun, 20 Nov 2005 22:03:34 +0100, Christoph Zwerschke [EMAIL PROTECTED] wrote: Ordering the keys isn't the normal case, and can be done easily when needed. That depends. Maybe I do not want

<    1   2   3   4   5   6   7   8   9   10   >