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
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:
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
> 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
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
[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
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...)
>
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:
> '
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
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
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
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
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
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
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
On the python3000 mailing list there was some discussion of a "comprehension
syntax" for reduce.
This inspired me the following proof-of-concept in pure python 2.5a1, although
I
don't know if it relies on an intended feature or a(n unintended) bug.
Cheers, BB
--
def ireduce(gen) :
"""
Wildemar Wildenburger wrote:
> Over the time I've seen lots of remarks about python that read like "a
> lot like lists in lisp" or "like the hashtable in java" or any other
> form of "like in ".
>
> Are there any concepts that python has not borrowed,
Esoterically speaking, you should better d
Julien Fiore wrote:
> Do you wand to install Pyrex on Windows ?
>
> Here is a step-by-step guide explaining:
>
> A) how to install Pyrex on Windows XP.
> B) how to compile a Pyrex module.
>
> Julien Fiore,
> U. of Geneva
Thanks. One detail missing : for this (step b3) to work smooth
[EMAIL PROTECTED] wrote:
> For the list [1,2,3,4], I'm looking for the following for k = 2:
>
> [[1,2], [3,4]]
> [[1,3], [2,4]]
> [[1,4], [2,3]]
>
> for k = 3:
>
> [[1,2,3], [4]]
> [[1,2,4], [3]]
> [[1,3,4], [2]]
> [[2,3,4], [1]]
>
def pickk(k,N,m=0) :
if k==1 :
return ((n,) for
I wrote:
>
> def pickk(k,N,m=0) :
> if k==1 :
> return ((n,) for n in range(m,N))
> else :
> return ((n,)+more for more in pickk(k-1,N,m+1)
> for n in range(m,more[0]))
>
> def partitionN(k,N) :
> subsets = [frozenset(S) for S in pickk(k,N)]
John Salerno wrote:
> Is there a way to assign multiple variables to the same value, but so
> that an identity test still evaluates to False?
>
> e.g.:
>
> >>> w = x = y = z = False
> >>> w
> False
> >>> x
> False
> >>> w == x
> True
> >>> w is x
> True # not sure if this is harmful
Steve R. Hastings wrote:
> So, don't test to see if something is equal to True or False:
>
> if 0 == False:
> pass # never executed; False and 0 do not directly compare
of course they do - ie isinstance(False,int) is True and False == 0
>
>
> You *could* do this, but I don't really recom
Grant Edwards wrote:
> Python knows how to count. :)
>
> def countFalse(seq):
> return len([v for v in seq if not v])
>
> def countTrue(seq):
> return len([v for v in seq if v])
>
> def truth_test(seq):
> return countTrue(seq) == 1
>
I'd suggest the more direct
def countFalse(seq
Steve R. Hastings wrote:
> len([v for v in seq if v]) # builds a list, then feeds it to len()
> len(v for v in seq if v) # gen obj feeds values to len one at a time
note that generators have no defined length - precisely because they feed
values
one at a time while you need them all together
Grant Edwards wrote:
> On 2006-05-02, Boris Borcic <[EMAIL PROTECTED]> wrote:
>> Grant Edwards wrote:
>>> Python knows how to count. :)
>>>
>>> def countFalse(seq):
>>> return len([v for v in seq if not v])
>>>
>>> def
John Salerno wrote:
> bruno at modulix wrote:
>
>> Now if I may ask: what is your actual problem ?
>
> Ok, since you're so curious. :)
>
> Here's a scan of the page from the puzzle book:
> http://johnjsalerno.com/spies.png
>
> Basically I'm reading this book to give me little things to try out
Jay Parlar wrote:
>
> On May 4, 2006, at 12:12 AM, [EMAIL PROTECTED] wrote:
> [...]
> Assume that you have the lines in a list called 'lines',
> as follows:
>
> lines = [
>"1SOME STRING ~ABC~12311232432D~20060401~",
>"3SOME STRING ~ACD~14353453554G~20060401~",
vdrab wrote:
>> """
>> E.g., after "a = 1;
>> b = 1",
>> a and b may or may not refer to the same object with the value one,
>> depending on the implementation,
>> """
>
> But when in a specific implementation this property _does_ hold for
> ints having value 1, I expect the
> same behavio
[EMAIL PROTECTED] wrote:
> Hi all,
>
> Does anybody know of a module that allows you to enumerate all the
> strings a particular regular expression describes?
>
> Cheers,
> -Blair
>
By hand write down a generator that will solve the simplest case of '.*' as a
regexp, and filter the output of th
Steve R. Hastings wrote:
> You could also use a function that counts all different values in a list,
> reducing the list to a dictionary whose keys are the unique values from
> the list. I got the idea from a discussion here on comp.lang.python; I
> called my version of it tally().
>
> d = tally
Ken Tilton wrote:
> "Now if you are like most
> people, you think that means X. It does not."
As far as natural language and understanding are concerned, "to mean" means
conformity to what most people understand, Humpty Dumpties notwithstanding.
Cheers.
--
http://mail.python.org/mailman/listi
Bill Atkins wrote:
>
> It's interesting how much people who don't have macros like to put
> them down and treat them as some arcane art that are too "*insane*"ly
> powerful to be used well.
>
> They're actually very straightforward and can often (shock of shocks!)
> make your code more readable,
Ken Tilton wrote:
>
>
> Boris Borcic wrote:
>> Ken Tilton wrote:
>>
>>> "Now if you are like most people, you think that means X. It does not."
>>
>>
>> As far as natural language and understanding are concerned, "to mean"
jayessay wrote:
> "Michele Simionato" <[EMAIL PROTECTED]> writes:
>
>> jayessay wrote:
>>> I was saying that you are mistaken in that pep-0343 could be used to
>>> implement dynamically scoped variables. That stands.
>> Proof by counter example:
>>
>> from __future__ import with_statement
>> impo
unpickling objects
just to pickle them again ?
TIA, Boris Borcic
--
http://mail.python.org/mailman/listinfo/python-list
Heiko Wundram wrote:
...
> As I've noticed that I find myself typing the latter quite often
> in code I write, it would only be sensible to add the corresponding
> syntax for the for statement:
>
> for node in tree if node.haschildren():
>
>
> as syntactic sugar f
Roy Smith wrote:
> I noticed something interesting today. In C++, you write:
>
> try {
>throw foo;
> } catch {
> }
>
> and all three keywords are verbs, so when you describe the code, you can
> use the same English words as in the program source, "You try to execute
> some code, but it thr
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
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
>> 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
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
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
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
[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.
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:
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
>
>
[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
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
[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 ...
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
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
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
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
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
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
> ...
>
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
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
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
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
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
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
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"
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
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
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
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
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
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
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
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/
seconded.
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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
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]
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
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
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
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
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
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
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.
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
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
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
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(
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
42, for instance.
Proof :
>>> 42 is not object
True
QED
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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):
...
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 :
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
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
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
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/
101 - 198 of 198 matches
Mail list logo