Re: how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ?

2014-04-10 Thread Boris Borcic
Boris Borcic wrote: Rustom Mody wrote: def fl1(l): return [y for x in l for y in x] # recursive flatten def fr(l): ... if not isinstance(l,list): return [l] ... return fl1([fr(x) for x in l]) For a short non-recursive procedure - not a function, modifies L in-place but none of its

Re: how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ?

2014-04-10 Thread Boris Borcic
Rustom Mody wrote: def fl1(l): return [y for x in l for y in x] # recursive flatten def fr(l): ... if not isinstance(l,list): return [l] ... return fl1([fr(x) for x in l]) For a short non-recursive procedure - not a function, modifies L in-place but none of its sublists. >>> def flat

Re: A and B but not C in list

2011-01-24 Thread Boris Borcic
Terry Reedy wrote: The straightforward code if a in L and b in L and c not in L and d not in L scans the list 4 times. of course for a single scan one can setify the list and write S=set(L) if a in S and b in S and c not in S and d not in S or even, I guess, something like {a,b} <= S and

Re: How convert list to nested dictionary?

2010-11-05 Thread Boris Borcic
Arnaud Delobelle wrote: macm writes: Hi Folks How convert list to nested dictionary? l ['k1', 'k2', 'k3', 'k4', 'k5'] result {'k1': {'k2': {'k3': {'k4': {'k5': {}} Regards macm reduce(lambda x,y: {y:x}, reversed(l), {}) d={} while L : d={L.pop():d} -- http://mail.python.org/

Re: Python Macros's Not the Power in OOo they should be ?

2010-09-23 Thread Boris Borcic
Lawrence D'Oliveiro wrote: flebber wrote: Has anyone had much success with python macro's. Or developing powerful macro's in an language? I did an application for my own use recently, involving automatically generating invoices in editable OOWriter format from my billing database. I gave up o

Re: List of lists surprising behaviour

2010-06-17 Thread Boris Borcic
candide wrote: So what is the right way to initialize to 0 a 2D array ? Is that way correct : >>> t=[[0 for _ in range(2)] for _ in range(3)] That's overkill :) You can skip the inner loop by using a list display, eg t=[[0,0] for _ in range(3)] It seems there is no more trouble now :

Re: pythonize this!

2010-06-16 Thread Boris Borcic
Ignacio Mondino wrote: On Tue, Jun 15, 2010 at 8:49 AM, superpollo wrote: goal (from e.c.m.): evaluate 1^2+2^2+3^2-4^2-5^2+6^2+7^2+8^2-9^2-10^2+...-2010^2, where each three consecutive + must be followed by two - (^ meaning ** in this context) my solution: s = 0 for i in range(1, 2011): ...

Re: An iteration idiom (Was: Re: [Guppy-pe-list] loading files containing multiple dumps)

2009-09-02 Thread Boris Borcic
Sverker Nilsson wrote: Sverker Nilsson wrote: It reads one Stat object at a time and wants to report something when there is no more to be read from the file. Hmm, am I right in thinking the above can more nicely be written as: >>> from guppy import hpy >>> h = hpy() >>> f = open(r'your.hp

Re: Making the case for repeat

2009-06-12 Thread Boris Borcic
Raymond Hettinger wrote: There is a natural inclination to do the opposite. We factor code to eliminate redundancy, but that is not always a good idea with an API. The goal for code factoring is to minimize redundancy. The goal for API design is having simple parts that are easily learned and c

Re: list comprehension question

2009-05-06 Thread Boris Borcic
Ross wrote: If I have a list of tuples a = [(1,2), (3,4), (5,6)], and I want to return a new list of each individual element in these tuples, I can do it with a nested for loop but when I try to do it using the list comprehension b = [j for j in i for i in a], my output is b = [5,5,5,6,6,6] inste

Re: Python to Perl transalators

2009-03-18 Thread Boris Borcic
Armin wrote: Why on earth would you want to? That'd be like translating Shakespeare into a bad rap song! lol, actually I would prefer a rap song over Shakespeare, so your analogy doesn't work there ;) Why, some people do prefer Perl over Python, so what's wrong with the analogy ? -- http

Re: Ban Xah Lee

2009-03-08 Thread Boris Borcic
seconded. -- http://mail.python.org/mailman/listinfo/python-list

Re: Themed TK (tk Tile) at last?!

2009-03-08 Thread Boris Borcic
Python Nutter wrote: Looks like we finally get tkinter GUI based programs according to Issue# 2983 in Python 3.1a so our programs don't look like something out of early 1980's Please don't confuse History gratuitously. Make that mid 90's. Cheers, BB -- http://mail.python.org/mailman/listinfo/

Re: Delete all items in the list

2009-02-26 Thread Boris Borcic
Chris Rebert wrote: On Thu, Feb 26, 2009 at 3:05 AM, Clarendon wrote: ... L=['a', 'b', 'c', 'a'] I want to delete all 'a's from the list. But if L.remove('a') only deletes the first 'a'. How do you delete all 'a's? There are several ways. I'd go with a list comprehension: and for a coupl

Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread Boris Borcic
itlist[i] = (x+(i*10) for i,s in (i,count()) for x in s) oops, that would be itlist[i] = (x+(i*10) for i,s in [(i,count())] for x in s) or equivalent, kind of ugly anyway. -- http://mail.python.org/mailman/listinfo/python-list

Re: lazy evaluation is sometimes too lazy... help please.

2009-01-16 Thread Boris Borcic
The minimal correction, I guess, is to write itlist[i] = (x+(i*10) for i in [i] for x in count()) instead of itlist[i] = (x+(i*10) for x in count()) although itlist[i] = (x+(i*10) for i,s in (i,count()) for x in s) will better mimic generalizations in the sense that the "minimal cor

Re: More elegant way to try running a function X times?

2008-11-20 Thread Boris Borcic
Tim Chase wrote: success = None for i in range(5): #Try to fetch public IP success = CheckIP() if success: break if not success: print "Exiting." sys.exit() Though a bit of an abuse, you can use if not any(CheckIP() for _ in range(5)): print "Exiting" sys.e

Re: More elegant way to try running a function X times?

2008-11-20 Thread Boris Borcic
Tim Chase wrote: success = None for i in range(5): #Try to fetch public IP success = CheckIP() if success: break if not success: print "Exiting." sys.exit() Though a bit of an abuse, you can use if not any(CheckIP() for _ in range(5)): print "Exiting" sys

Re: Function to Add List Elements?

2008-10-23 Thread Boris Borcic
Chris Rebert wrote: On Wed, Oct 22, 2008 at 12:59 PM, Henry Chang <[EMAIL PROTECTED]> wrote: This seems like a simple problem, but I can't find a simple solution. Suppose I have two lists of integers. List A = [A1, A2, A3] List B = [B1, B2, B3] I just simply want a new list, such as: List C

Re: Append a new value to dict

2008-10-16 Thread Boris Borcic
Kirk Strauser wrote: While we're on the subject, use keyword arguments to dict like: foo.update(dict(quux='blah', baz='bearophile', jdd='dict')) was *much* slower, at 11.8s. Presumably you would save half of that time by writing simply foo.update(quux='blah', baz='bearophile', jdd

Re: ABCs -> infix syntax for isinstance() ?

2008-10-09 Thread Boris Borcic
Terry Reedy wrote: Boris Borcic wrote: ... - allowing containment tests, ie "x in Number" to invoke isinstance() in the background when the container is of type . My brain is too muddled by flu at the moment, to see whether Guido's fabled time machine allowed him to already

Re: ABCs -> infix syntax for isinstance() ?

2008-10-08 Thread Boris Borcic
Bruno Desthuilliers wrote: [EMAIL PROTECTED] a écrit : ... A intriguing wider proposition would be to transpose Ruby's notion of "Open Classes" to Python built-in metaclasses (or just to type itself ?). No, thanks. Even the Ruby guys start to think making evrything open may not be such a goo

Re: ABCs -> infix syntax for isinstance() ?

2008-10-07 Thread Boris Borcic
Bruno Desthuilliers wrote: Boris Borcic a écrit : Given the ABC innovation, maybe an infix syntax for isinstance() would be good. Possibilities : - stealing "is" away from object identity. As a motivation, true use cases for testing object identity are rare; "x is None"

ABCs -> infix syntax for isinstance() ?

2008-10-03 Thread Boris Borcic
Given the ABC innovation, maybe an infix syntax for isinstance() would be good. Possibilities : - stealing "is" away from object identity. As a motivation, true use cases for testing object identity are rare; forcing the usage of a function or method to test it, would dissuade abuse. - allow

Re: What is not objects in Python?

2008-10-01 Thread Boris Borcic
42, for instance. Proof : >>> 42 is not object True QED -- http://mail.python.org/mailman/listinfo/python-list

Re: dict generator question

2008-09-19 Thread Boris Borcic
Gerard flanagan wrote: George Sakkis wrote: .. Note that this works correctly only if the versions are already sorted by major version. Yes, I should have mentioned it. Here's a fuller example below. There's maybe better ways of sorting version numbers, but this is what I do. Indeed, you

Re: recursion gotcha?

2008-09-14 Thread Boris Borcic
cnb wrote: this recursive definition of sum thrumped me, is this some sort of gotcha or am I just braindead today? and yes i know this is easy a a for x in xs acc += x or just using the builtin. def suma(xs, acc=0): if len(xs) == 0: acc else: suma(

Re: Injecting new names into the above frame

2008-09-13 Thread Boris Borcic
Why don't you use import and __import__() ? - They seem designed for such an application. I mean, I am not against vicious hacks for the fun of them, but not if they serve the illusion that what they do can't (easily) be achieved other ways. Cheers, BB Peter Waller wrote: Dear Pythoners, I

''.join woes - Re: max(), sum(), next()

2008-09-13 Thread Boris Borcic
I wrote: Tino Wildenhain wrote: [...] sum(['a','b'],'') : sum() can't sum strings [use ''.join(seq) instead] Yes which is a bit bad anyway. I don't think hard wiring it is such a nice idea. You know, walks like a duck, smells like a duck... If it makes sense to handle things differently

Re: max(), sum(), next()

2008-09-13 Thread Boris Borcic
Tino Wildenhain wrote: Hi, Luis Zarrabeitia wrote: Quoting Laszlo Nagy <[EMAIL PROTECTED]>: ... Even better: help(sum) shows === sum(...) sum(sequence, start=0) -> value Returns the sum of a sequence of numbers (NOT strings) plus the value of parameter 'start'. When the

Re: max(), sum(), next()

2008-09-09 Thread Boris Borcic
castironpi wrote: On Sep 8, 8:54 am, Boris Borcic <[EMAIL PROTECTED]> wrote: David C. Ullrich wrote: (ii) If A is a subset of B then we should have max(A) <= max(B). This requires that max(empty set) be something that's smaller than everything else. So we give up on that.

Re: max(), sum(), next()

2008-09-08 Thread Boris Borcic
David C. Ullrich wrote: (ii) If A is a subset of B then we should have max(A) <= max(B). This requires that max(empty set) be something that's smaller than everything else. So we give up on that. Er, what about instances of variations/elaborations on class Smaller(object) : __cmp__ = lambda

Re: Lining Up and PaddingTwo Similar Lists

2008-08-29 Thread Boris Borcic
D,T=[dict((x.split('.')[0],x) for x in X) for X in (dat,txt)] for k in sorted(set(D).union(T)) : for S in D,T : print '%-8s' % S.get(k,'None'), print HTH W. eWatson wrote: Maybe there's some function like zip or map that does this. If not, it's probably fairly easy to do with pu

Re: like a "for loop" for a string

2008-08-18 Thread Boris Borcic
Alexnb wrote: Uhm, "string" and "non-string" are just that, words within the string. Here shall I dumb it down for you? string = "yes text1 yes text2 yes text3 no text4 yes text5+more Text yes text6 no text7 yes text8" It doesn't matter what is in the string, I want to be able to know exactly

Re: Is there a faster way to do this?

2008-08-06 Thread Boris Borcic
Is your product ID always the 3rd and last item on the line ? Else your output won't separate IDs. And how does output = open(output_file,'w') for x in set(line.split(',')[2] for line in open(input_file)) : output.write(x) output.close() behave ? [EMAIL PROTECTED] wrote: I have a csv fil

Re: 2d graphics - what module to use?

2008-07-25 Thread Boris Borcic
Pierre Dagenais wrote: What is the easiest way to draw to a window? I'd like to draw something like sine waves from a mathematical equation. Newbie to python. -- http://mail.python.org/mailman/listinfo/python-list For very simple things, the standard module turtle might be your best bet. BB

Re: listcomprehension, add elements?

2008-06-23 Thread Boris Borcic
John Machin wrote: Instead of sum(a + b for a, b in zip(foo, bar)) why not use sum(foo) + sum(bar) ? or even sum(foo+bar) as may apply. Cheers, BB -- http://mail.python.org/mailman/listinfo/python-list

Re: slicing lists

2008-05-08 Thread Boris Borcic
Yves Dorfsman wrote: So would it be a worthy addition to python, to add it right in the core of the language, and hopefully in an efficient manner ? Note that the s[0,2:6] syntax is currently allowed because of the distinct semantics that the Numeric module and its successors numarray and

Re: parameters to lambda's executed at run time.

2008-05-06 Thread Boris Borcic
One way : >>> from functools import partial >>> def func(item) : print item >>> llist = [partial(func,item) for item in range(5)] >>> for thing in llist : thing() 0 1 2 3 4 wyleu wrote: I'm trying to supply parameters to a function that is called at a later time as in the code below: llist

Re: computing with characters

2008-05-06 Thread Boris Borcic
Duncan Booth wrote: Torsten Bronger <[EMAIL PROTECTED]> wrote: The biggest ugliness though is ",".join(). No idea why this should be better than join(list, separator=" "). Besides, ",".join(u"x") yields an unicode object. This is confusing (but will probably go away with Python 3). It is o

Re: get number that is raised to the power of

2008-05-02 Thread Boris Borcic
Marc 'BlackJack' Rintsch wrote: On Fri, 02 May 2008 19:19:07 +1000, Astan Chee wrote: Hi, Im not sure if this is more of a math question or a python question. I have a variable in python: >>> v = 10.0**n is there a way to find the value of n if i know only v aside from str(v).split('+')[1]

Re: __iter__ yield

2008-03-10 Thread Boris Borcic
Paul Hankin wrote: > On Mar 10, 3:12 am, George Sakkis <[EMAIL PROTECTED]> wrote: >> On Mar 9, 7:37 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: >> >> >> >>> On Mar 9, 8:58 pm, duccio <[EMAIL PROTECTED]> wrote: Someone knows if it's possible to make this __iter__ function with just one 'yie

Re: Making string-formatting smarter by handling generators?

2008-02-27 Thread Boris Borcic
D'Arcy J.M. Cain wrote: >> I find I hit it mostly with calls to map() where I want to apply >> some transform (as above) to all the items in a list of >> parameters such as >> >>"%s=%s&%s=%s" % map(urllib.quote, params) > > Isn't map() deprecated? The above can be done with; > > "%s=%s

Re: Is crawling the stack "bad"? Why?

2008-02-25 Thread Boris Borcic
Paul Rubin wrote: > Russell Warren <[EMAIL PROTECTED]> writes: >> That is exactly where I started (creating my own request handler, >> snagging the IP address and stashing it), but I couldn't come up with >> a stash location that would work for a threaded server. > > How about a dictionary indexed

Re: Seemingly odd 'is' comparison.

2008-02-19 Thread Boris Borcic
Duncan Booth wrote: > Boris Borcic <[EMAIL PROTECTED]> wrote: >> Arnaud Delobelle wrote: >>> Whereas when "3.0*1.0 is 3.0" is evaluated, *two* different float >>> objects are put on the stack and compared (LOAD_CONST 3 / LOAD_CONST >>> 1 / COM

Re: Seemingly odd 'is' comparison.

2008-02-19 Thread Boris Borcic
Arnaud Delobelle wrote: > On Feb 13, 10:19 pm, Tobiah <[EMAIL PROTECTED]> wrote: > print float(3.0) is float(3.0) >> True > print float(3.0 * 1.0) is float(3.0) >> False > > [You don't need to wrap your floats in float()] > def f(): > ... return 3.0 is 3.0, 3.0*1.0 is 3.0 > ... >

Re: flattening a dict

2008-02-19 Thread Boris Borcic
Duncan Booth wrote: > In this particular case I think the lambda does contribute to the > obfuscation. Yes, they are single expressions, but only because that > have been contorted to become single expressions. The first two return > generators, so if you don't force them into a lambda you can wr

Re: flattening a dict

2008-02-18 Thread Boris Borcic
Duncan Booth wrote: > Boris Borcic <[EMAIL PROTECTED]> wrote: > >> It is more elementary in the mathematician's sense, and therefore >> preferable all other things being equal, imo. I've tried to split >> 'gen' but I can't say the result is s

Re: flattening a dict

2008-02-18 Thread Boris Borcic
Arnaud Delobelle wrote: > On Feb 17, 4:03 pm, Boris Borcic <[EMAIL PROTECTED]> wrote: >> George Sakkis wrote: >>> On Feb 17, 7:51 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >>>> BTW, I keep using the idiom itertools.chain(*iterable). I guess that

Re: flattening a dict

2008-02-17 Thread Boris Borcic
George Sakkis wrote: > On Feb 17, 7:51 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > >> BTW, I keep using the idiom itertools.chain(*iterable). I guess that >> during function calls *iterable gets expanded to a tuple. Wouldn't it >> be nice to have an equivalent one-argument function that ta

Re: flattening a dict

2008-02-17 Thread Boris Borcic
Arnaud Delobelle wrote: > > In Python you can do anything, even ...pass the Turing test with a one-liner. Back after 9/11, when US patriotism was the rage, Python knew how to answer correctly the query filter(lambda W : W not in 'ILLITERATE','BULLSHIT') And Python 3.0 slated for next August o

Re: An idea for fast function composition

2008-02-16 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > On Feb 16, 3:47 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >> Hi all, >> >> Recently there was a thread about function composition in Python (and >> this was probably not the first). The fast way to create a >> (anonymous) composite function >> >> f1 o f2 o ...

Re: ways to declare empty set variable

2008-02-16 Thread Boris Borcic
Steve Holden wrote: > Boris Borcic wrote: >> [EMAIL PROTECTED] wrote: >>> ...Missing that, I think dict() and set() and >>> tuple() and list() look better than using {} for the empty dict and >>> {/} for the empty set and () for empty tuple (or {} for the empty

Re: ways to declare empty set variable

2008-02-16 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > > ...Missing that, I think dict() and set() and > tuple() and list() look better than using {} for the empty dict and > {/} for the empty set and () for empty tuple (or {} for the empty dict > and set() for the empty set). The problem I have with them is in no way the l

Re: How to identify which numbers in a list are within each others' range

2008-02-08 Thread Boris Borcic
Boris Borcic wrote: > Arnaud Delobelle wrote: > (...) >> >> from itertools import chain >> >> def overlaps(lst): >> bounds = chain(*(((x[1],i), (x[2], i)) for i,x in enumerate(lst))) > > imho, this is a uselessly painful equivalent of > >

Re: How to identify which numbers in a list are within each others' range

2008-02-08 Thread Boris Borcic
Arnaud Delobelle wrote: (...) > > from itertools import chain > > def overlaps(lst): > bounds = chain(*(((x[1],i), (x[2], i)) for i,x in enumerate(lst))) imho, this is a uselessly painful equivalent of bounds = ((x[k],i) for i,x in enumerate(lst) for k in (1,2)) Cheers, BB -- http:

Re: future multi-threading for-loops

2008-02-05 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > On Feb 5, 12:26 am, Gabriel Genellina <[EMAIL PROTECTED]> wrote: >> On 5 feb, 03:46, [EMAIL PROTECTED] wrote: >> >>> Some timing stats: On Windows XP, Python 3.0a2. (...) >>> Are threads an OS bottleneck? >> I don't understand your threading issues, but I would not use 3.

Re: find nearest time in datetime list

2008-01-30 Thread Boris Borcic
washakie wrote: > Hello, > > I have a list of datetime objects: DTlist, I have another single datetime > object: dt, ... I need to find the nearest DTlist[i] to the dt is > there a simple way to do this? There isn't necessarily an exact match... > > Thanks! > .john > min(DTlist,key=lambd

Re: optional static typing for Python

2008-01-28 Thread Boris Borcic
Wish you'd opted out of typing all that static. BB Russ P. wrote: (...) > > What is that supposed to mean? > > Oh, I almost forgot. I'm supposed to sit here and be polite while > clueless dolts make wise cracks. Sorry, but I haven't yet mastered > that level of self-control. > > I would just l

Re: Python self-evaluating strings

2008-01-27 Thread Boris Borcic
Now there's always that style : >>> print x Traceback (most recent call last): File "", line 1, in eval(x) File "", line 2 Traceback (most recent call last): ^ SyntaxError: invalid syntax >>> eval(x) Traceback (most recent call last): File "", lin

Re: sudoku solver in Python ...

2008-01-25 Thread Boris Borcic
>> http://norvig.com/sudoku.html (...) > Below is the "winner" of my hacking for an as fast as > possible 110% pure python (no imports at all!) comprehensive sudoku > solver under 50 LOCs, back in 2006. Performance is comparable to the > solver you advertize - numbers are slightly better, but

Re: sudoku solver in Python ...

2008-01-24 Thread Boris Borcic
Shawn Milochik wrote: > On Jan 23, 2008, at 10:02 PM, Derek Marshall wrote: > >> This is just for fun, in case someone would be interested and because >> I haven't had the pleasure of posting anything here in many years ... >> >> http://derek.marshall.googlepages.com/pythonsudokusolver >> >> A

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread Boris Borcic
I am surprised nobody pointed out explicitely that True==1 and False==0 so that for instance 5*(True+True)==10 and even (but implementation-dependent) : 5*(True+True) is 10 BB -- http://mail.python.org/mailman/listinfo/python-list

Re: convert pdf to png

2007-12-26 Thread Boris Borcic
Carl K wrote: > Rob Wolfe wrote: >> Carl K <[EMAIL PROTECTED]> writes: >> >>> I need to take the take the pdf output from reportlab and create a >>> preview image for a web page. so png or something. I am sure >>> ghostscript will be involved. I am guessing PIL or ImageMagic ? >>> >>> all sugesti

Re: Distinguishing attributes and methods

2007-12-19 Thread Boris Borcic
MonkeeSage wrote: > what am I missing? To my eyes, when you write: >I think it muddies the water to say that a.a() and a.a are the same >thing--obviously they are not. In the common case, the first is a >method, and the second is a variable. What you are most obviously missing is what's shown

Re: .NET and Python Integration Problem and PDF Library (Need Help and Suggestions)

2007-12-18 Thread Boris Borcic
Ravi Kumar wrote: > - your opinion with available PDF Libraries, that are best among. Also > which library to use for Windows server platform (there is limitation > on installing long chain libraries that include other deep > dependencies too). A pure python PDF library would be good, but which > o

Re: Converting Excel time-format (hours since 1.1.1901)

2007-12-07 Thread Boris Borcic
Dirk Hagemann wrote: > (3566839/24)/365 = 407 - YES I did this calculation too and was > surprised. But if you try this out in MS Excel: > ="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) (put > 3566839 in field A1 and switch the format of the result-fieldby right- > click on it to

Re: "Python" is not a good name, should rename to "Athon"

2007-12-06 Thread Boris Borcic
Piet van Oostrum wrote: >> "Adrian Cherry" <[EMAIL PROTECTED]> (AC) wrote: > >> AC> For that matter C# is no better, I thought that # was pronounced >> AC> hash, I still refer to C# as C-hash. > > Are you musically illiterate? Note that the notation for the note (!) isn't universal. French

Re: "Python" is not a good name, should rename to "Athon"

2007-12-05 Thread Boris Borcic
Russ P. wrote: > If I had invented Python, I would have called it Newton or Euler, > arguably the greatest scientist and mathematician ever, respectively. This makes your taste on the matter dubious. Such choice of a name implies either a claim to the fame of the Person that's devoid of substanc

Re: "Python" is not a good name, should rename to "Athon"

2007-12-05 Thread Boris Borcic
Russ P. wrote: > Speaking of stupid names, what does "C++" mean? According to Special Relativity, C++ is a contradiction in terms :) -- http://mail.python.org/mailman/listinfo/python-list

Re: How to write Regular Expression for recursive matching?

2007-11-26 Thread Boris Borcic
lisong wrote: > Hi All, > > I have problem to split a string like this: > > 'abc.defg.hij.klmnop' > > and I want to get all substrings with only one '.' in mid. so the > output I expect is : > > 'abc.defg', 'defg.hij', 'hij.klmnop' > > a simple regular expression '\w+.\w' will only return: > '

Re: eof

2007-11-26 Thread Boris Borcic
ZeD wrote: > Grant Edwards wrote: > >> The user-defined xor is operates on "logical" boolean values. >> The one in the operator module is a bitwise operator. > > def xor(a, b): > return bool(a) ^ bool(b) > > seems more explicit to me. > maybe, to make "more" explicit (too much, onestly...) >

Re: eof

2007-11-26 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > def xor(a, b): > return a and not b or b and not a >>> from operator import xor >>> help(xor) Help on built-in function xor in module operator: xor(...) xor(a, b) -- Same as a ^ b. -- http://mail.python.org/mailman/listinfo/python-list

Re: eof

2007-11-22 Thread Boris Borcic
Duncan Booth wrote: > Nice, thank you. Welcome. > But why 'count(chunksize)' rather than just 'count()'? To number the first chunk 1, etc. using count() starts with 0. Matter of taste. > Does it make a difference anywhere? And I'd recommend using // rather than > / otherwise it breaks if you

Re: eof

2007-11-22 Thread Boris Borcic
> def chunked(chunksize,f) : > from itertools import count,groupby > counter=count(chunksize).next > return groupby(f,lambda _ : counter()/chunksize) And more to the point, no "yield" for Alexy to mock :) -- http://mail.python.org/mailman/listinfo/python-list

Re: eof

2007-11-22 Thread Boris Borcic
Duncan Booth wrote: > import itertools > def chunks(f, size): > iterator = iter(f) > def onechunk(line): > yield line > for line in itertools.islice(iterator, size-1): > yield line > for line in iterator: > yield onechunk(line) Quite simpler, and pro

Re: Finding lowest value in dictionary of objects, how?

2007-11-19 Thread Boris Borcic
davenet wrote: > Hi, > > I'm new to Python and working on a school assignment. > > I have setup a dictionary where the keys point to an object. Each > object has two member variables. I need to find the smallest value > contained in this group of objects. > > The objects are defined as follows:

Re: sorting contacts alphabetically, sorted by surname

2007-11-16 Thread Boris Borcic
Wow J. Clifford Dyer wrote: > On Fri, Nov 16, 2007 at 12:31:19PM +, Marie Hughes wrote regarding > sorting contacts alphabetically, sorted by surname: >>HI >> >>I have to write a program that contains a text file in the following >>format: >> >>AcademicPosition

Re: sorting contacts alphabetically, sorted by surname

2007-11-16 Thread Boris Borcic
Marie Hughes wrote: > HI > > I have to write a program that contains a text file in the following format: > > AcademicPositionRoom Ext. Email > Prof Marie Maguire Head of > School M9002 [EMAIL PROTECTED] > > > And

Re: implement random selection in Python

2007-11-16 Thread Boris Borcic
Boris Borcic wrote: > Bruza wrote: >> No. That does not solve the problem. What I want is a function >> >> def randomPick(n, the_items): >> >> which will return n DISTINCT items from "the_items" such that >> the n items returned are according to t

Re: implement random selection in Python

2007-11-16 Thread Boris Borcic
Bruza wrote: > No. That does not solve the problem. What I want is a function > > def randomPick(n, the_items): > > which will return n DISTINCT items from "the_items" such that > the n items returned are according to their probabilities specified > in the (item, pro) elements inside "the_items

Re: implement random selection in Python

2007-11-16 Thread Boris Borcic
Bruza wrote: > No. That does not solve the problem. What I want is a function > > def randomPick(n, the_items): > > which will return n DISTINCT items from "the_items" such that > the n items returned are according to their probabilities specified > in the (item, pro) elements inside "the_items

Re: Using python as primary language

2007-11-09 Thread Boris Borcic
Michel Albert wrote: > > What I meant was that one should be able to "draw" a report template. > Basically a graphical user interface for RML in this case. I > personally would opt for writing RML or whatever code myself. But it's > impossible to convice my boss. The dialog usually goes like this:

Re: Closure/binding problem or misunderstanding

2007-11-09 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > If I run the following code: > > class path(object): > def __init__(self, **subdirs): > for name, path in subdirs.iteritems(): > def getpath(): > return path > setattr(self, name, getpath) > > export = path( > one

Re: How to link different site-packages to different Python?

2007-11-09 Thread Boris Borcic
Davy wrote: > Hi all, > > I have Python 2.4 and 2.5 in my PC. And PythonWin is installed as IDE. > > When I tried to use site-packages "Numpy", I installed the both > version (i.e. for 2.4 and 2.5). > > Python 2.4 and Numpy for it work together well. > > But when I type "from numpy import *" in

Re: permuting over nested dicts?

2007-11-08 Thread Boris Borcic
Boris Borcic wrote: > Christian Meesters wrote: >> Hoi, >> >> I have the following data structure (of variable size actually, to make >> things simple, just that one): >> d = {'a': {'x':[1,2,3], 'y':[4,5,6]}, >>

Re: What about a Python Tree container?

2007-11-06 Thread Boris Borcic
Roc Zhou wrote: > Hello, Hello, This post is too long. The right place for such is as a python reciepe on ActiveState. BTW, I bet you can find 3+ equivalents to you Tree type in the recorded reciepes. Regards, BB -- http://mail.python.org/mailman/listinfo/python-list

Re: Trouble with for loop

2007-11-06 Thread Boris Borcic
Shriphani wrote: > On Nov 6, 3:09 pm, Ant <[EMAIL PROTECTED]> wrote: >> On Nov 6, 9:59 am, Shriphani <[EMAIL PROTECTED]> wrote: >> ... >> >>> My main intention is to state that each of the variables namely a, b, >>> c, ## can take value from 1 to 9. >>> How do I go about this ? >> It sounds like yo

Re: List to Tuple and Tuple to List?

2007-11-06 Thread Boris Borcic
Davy wrote: > Hi all, > > I am curious about whether there is function to fransform pure List to > pure Tuple and pure Tuple to pure List? > > For example, > > I have list L = [[1,2,3],[4,5,6]] > something list2tuple() will have T=list2tuple(L)=((1,2,3),(4,5,6)) > > And the tuple2list() > > An

Re: How to use list as key of dictionary?

2007-11-06 Thread Boris Borcic
You could also index on the repr() of your objects, which is an immutable str value. Davy wrote: > And there may be more complex list(vector like 3 or 4 dimentional data > structure), is there any easy method to tackle this problem? > > Any suggestions are welcome! > > Best regards, > Davy > >

Re: How to use list as key of dictionary?

2007-11-05 Thread Boris Borcic
Davy wrote: > Hi all, > > We know that list cannot be used as key of dictionary. Yeah, but do we know why ? > So, how to work > around it? That's a subsidiary question. > > For example, there is random list like l=[1,323,54,67]. Don't use 1owercase L as a variab1e name, p1ease ! > > Any su

Re: new style class

2007-11-02 Thread Boris Borcic
gert wrote: > Could not one of you just say "@staticmethod" for once damnit :) > I did, did I not ? -- http://mail.python.org/mailman/listinfo/python-list

Re: new style class

2007-11-02 Thread Boris Borcic
gert wrote: [...] Why doesn't this new style class work in python 2.5.1 ? >>> why should it ? >> I don't know I thought it was supported from 2.2? > > oops the code is like this but doesn't work > > class Test(object): > > def m1(self,v): > return v > > def m2(v): >

Re: new style class

2007-11-02 Thread Boris Borcic
gert wrote: > class Test(object): > > def execute(self,v): > return v > > def escape(v): > return v > > if __name__ == '__main__': > gert = Test() > print gert.m1('1') > print Test.m2('2') > > Why doesn't this new style class work in python 2.5.1 ? > why s

Re: Need some help...

2007-11-02 Thread Boris Borcic
Ricardo Aráoz wrote: > Boris Borcic wrote: >> Ricardo Aráoz wrote: >>> Boris Borcic wrote: >>>> [EMAIL PROTECTED] wrote: >>>>> I want to create a program that I type in a word. >>>>> >>>>> for example... >>

Re: setting and getting column in numpymatrix

2007-11-01 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > hi > i am looking for an efficient way to get a specific column of a > numpy.matrix .. > also i want to set a column of the matrix with a given set of > values ..i couldn't find any methods for this in matrix doc..do i have > to write the functions from scratch? > >

Re: Need some help...

2007-11-01 Thread Boris Borcic
Ricardo Aráoz wrote: > Boris Borcic wrote: >> [EMAIL PROTECTED] wrote: >>> I want to create a program that I type in a word. >>> >>> for example... >>> >>> chaos >>> >>> each letter equals a number >>> >>&g

Re: permuting over nested dicts?

2007-11-01 Thread Boris Borcic
Christian Meesters wrote: > Hoi, > > I have the following data structure (of variable size actually, to make > things simple, just that one): > d = {'a': {'x':[1,2,3], 'y':[4,5,6]}, > 'b': {'x':[7,8,9], 'y':[10,11,12]}} > This can be read as a dict of possibilities: The entities 'a' and 'b' h

Re: Iteration for Factorials

2007-10-30 Thread Boris Borcic
Py-Fun wrote: > I'm stuck trying to write a function that generates a factorial of a > number using iteration and not recursion. Any simple ideas would be > appreciated. > fact = lambda n : len(map([1].__imul__,range(1,n+1))[0]) hth :) BB -- http://mail.python.org/mailman/listinfo/python-list

Re: Need some help...

2007-10-30 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > I want to create a program that I type in a word. > > for example... > > chaos > > each letter equals a number > > A=1 > B=20 > > and so on. > > So Chaos would be > > C=13 H=4 A=1 O=7 S=5 > > I want to then have those numbers > 13+4+1+7+5 added together to be

  1   2   >