rly.
In the shell, type 'help(reload)'. This might help.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
time insertion anywhere in the list.
>
> It's on the shelf between the jar of phlogiston and the perpetual
> motion machine.
I recommend a quick glance at any article on linked list.
Here's one: http://en.wikipedia.org/wiki/Linked_list
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
, 54, 54, 54, 54, 54]
Instead you want imap(randrange, repeat(n, p)):
>>> map(randrange, repeat(100, 10))
[69, 68, 81, 26, 60, 76, 40, 55, 76, 75]
I don't understand why you make the Python version so complicated.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
f __gt__(self, other):
return self.compare(other, operator.gt)
# etc...
This way the LarchTree object doesn't interpret the comparison
operators, just passes them on to its elements.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
e whole weekend :)
> Thanks,
> Thomas
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
of integers, they need
to be kept in normalised form.
* Nobody uses big fractions apart from mathematicians (and maybe
bookmakers?).
* Having yet another numerical type would make it difficult what
type to expect from a calculation.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
d wondered why?
>
> > What contrib?
>
> contrib section of the archive, as opposed to main
Are you refering to debian packages for python? In this case
you may be better off posting on one of the debian mailing lists.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
> If I've to build a tree, please give me resources and/or examples of
> what physically is a tree and how to build on python.
>
> Thanks :)
You can use a parser generator to build the syntax tree that you want.
See http://wiki.python.org/moin/LanguageParsing for a list.
Perhaps
nd(*val) if val else it.next()
co, val = n[0], n[1:]
it = fibers.get(co)
if it is None:
fibers[co] = it = co()
except StopIteration:
return val[0] if val else None
# Now the two 'fibers'
def f1():
print "f1 start"
On Dec 22, 2:37 pm, Duncan Booth <[EMAIL PROTECTED]> wrote:
> Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> > I am not really familiar with ruby but these fibers seem to be some
> > sort of coroutines. Since python 2.5, generators can be sent values,
> > this
gt; >>> s = Spam('spam and eggs', 'tomato', 'beans are off')
>
> __new__ ('spam and eggs', 'tomato', 'beans are off')
> __init__ ('spam and eggs', 'tomato', 'beans are off')
>
> Is there any way to do this, or am I all outta luck?
>
> --
> Steven
The ususal way is to override the __call__ method of the metaclass.
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ble
Traceback (most recent call last):
File "", line 1, in
File "tuple.py", line 4, in __setitem__
raise TypeError("'mytuple' object is immutable")
TypeError: 'mytuple' object is immutable
>>> a
([1, 3], 2)
It wouldn't slow anything down I suppose, just make some currently
failing code succeed.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Dec 24, 4:08 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
[...]
> class mytuple(tuple):
> "It's ok to do t[i] = obj as long as t[i] was already obj"
> def __setitem__(self, i, val):
> if self[i] is not val:
> raise TypeError(&qu
this thread.
* It gave a motivation for the 'mytuple' class.
I'm not sure what I think about it yet :)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
is mutable
a += c # equivalent to a.__iadd__(c)
b is a # -> True
OTOH augmented assignent are a slight optimisation:
a[i] += 1
will look for the value of a and i only once and duplicate them on the
stack, whereas
a[i] = a[i] + 1
will need to resolve a and i twice (which can be costly if a and i are
globals)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
bout the current behaviour is that it is easy to reason
with (once you know what happens), even though you almost have to get
bitten once. But using this to have static variable is extremely ugly
IMHO.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
:
def foo(self): return 'instance foo'
@classmethod
def classfoo(cls): return 'class foo'
def do(x):
if isinstance(x, type):
return x.classfoo()
else:
return x.foo()
Then:
>>> bar = Bar()
>>> do(bar)
'instance foo'
>>> do(Bar)
'class foo'
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 1, 5:26 am, NickC <[EMAIL PROTECTED]> wrote:
> On Jan 1, 3:22 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
>
> > On Dec 31, 10:58 am, Odalrick <[EMAIL PROTECTED]> wrote:
>
> > > I'm surprised noone has said anything about the why of default
kwargs.setdefault(name, val)
return f(*args, **kwargs)
return decorated
return decorator
Here is your example:
>>> z=1
>>> @default(z=z)
... def foo(a, z):
... print a + z
...
>>> z=None
>>> foo(3)
4
Another example, using mutables:
>>> @default(history=[])
... def bar(x, history):
... history.append(x)
... return list(history)
...
>>> map(bar, 'spam')
[['s'], ['s', 'p'], ['s', 'p', 'a'], ['s', 'p', 'a', 'm']]
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
now.year)
> if os.path.exists(filename):
> candidates = ("%s.%d" % (filename, x) for x in count(1))
> filename = dropwhile(os.path.exists, candidates).next()
>
> Much clearer than the alternatives I think, please keep dropwhile and
> takewhile in ite
was
the case with instances of old-style classes. So in your case
isinstance(MyClass(), Exception) will return True.
> Is there one, or is
> the distinction between traditional classes and built-in types only
> going to get more and more hazy?
I'm not sure what you mean here.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
setattr(cls, methodname, types.MethodType(_f, None, cls))
Of course this looks more like your first version, which trims down to
the following and is probably a better option:
def enhance_all_methods(cls, replacement):
for methodname in cls.__dict__:
if not methodname.s
is actually
std::set< T, std::less >
So make your own less_complex() function (for example, use
lexicographic order), std::set should give you
a set of complex numbers (sorry if some syntax is incorrect I haven't
done any C++ for a while :)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
f complex numbers. Any total order will do, the easiest to pick
being lexicographical as already pointed out, i.e.
a+bi < c + di iff a < c or a == c and b < d
> Which is bigger, 4+2j or 2+4j?
4+2j, lexicographically!
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ent call last):
> File "", line 1, in ?
> TypeError: an integer is required
>
> Now it's no longer a syntax error but I don't see why it's different?
Same as above, though I don't understand why you get a SyntaxError for
T and a TypeError for R. AFAICT both shoult give a TypeError.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
6, 15: 101, 17:
109, 19: 97}
>>> p = picker(range(20), lambda x: False, 10)
>>> p.next()
Traceback (most recent call last):
File "", line 1, in
StopIteration
I don't know if there is a good idea in there, I'll let you be the
judge :)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 5, 8:50 pm, Paul Hankin <[EMAIL PROTECTED]> wrote:
> On Jan 5, 5:12 pm, Paul Hankin <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Jan 5, 4:14 pm, [EMAIL PROTECTED] wrote:
>
> > > On Jan 5, 5:07 pm, [EMAIL PROTECTED] wrote:
>
> > > > Hello,
x86_64" $(SRCS) $(LDFLAGS) $
(LIBS)
Now that I look at this, I don' know if both are necessary... But it
worked for me.
There was a discussion to the mod_python mailing list in october 2007:
http://www.modpython.org/pipermail/mod_python/2007-October/
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
on't work here).
Note that the 'nonlocal' keyword solves this problem in py3k:
Python 3.0a1+ (py3k:59330, Dec 4 2007, 18:44:39)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def inc(j):
... def f():
... nonlocal j
... j += 1
... return j
... return f
...
>>> i = inc(3)
>>> i()
4
>>> i()
5
>>>
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
gen = repeat(default, len(iterables) - 1)
return izip(*[chain(it, repeatnext(defaultgen)) for it in
iterables])
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
he staticmethod decorator's role is to 'flag up' the
method as static for further processing when type(C).__new__ is
called.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ould compile to:
class A:
a = 42
def _genexpr(_a):
for _ in "a":
yield _a
list(_genexpr(a))
Which would behave as the OP expected (and I think as it is reasonable
to expect if one doesn't know about how genexprs are implemented).
Other reasons why I think this is desirable are exposed (maybe not
very convincingly) in this post to python-ideas.
http://mail.python.org/pipermail/python-ideas/2007-December/001260.html
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
> del(argdict[key])
> else:
> retval = default
> return retval
>
Dictionaries already have a method for this. It's called pop. It's a
good idea to have a look at methods of builtin types before
reimplementing the wheel!
Grab(argdict, key, default) is argdict.pop(key, default)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
re seems to be about one message a week about this. Indeed I
reckon the greatest benefit of early binding of default function
arguments is that it attracts lots of new people to comp.lang.python.
> It's quiet elegant way of creating cache.
IMHO, calling it 'elegant' is pushin
untown(numbers, target) -> None -- print all countdown
solutions"""
for dummy in calc(numbers, print_filter(target)): pass
def best_countdown(numbers, target):
"""best_countdown(numbers, target) -> str -- return shortest
solution"""
3))*(2+1))
283 = (3+(((5*4)*2)*(6+1)))
284 : can't be done
For 2, 3, 5, 8, 9, 10, the smallest unreachable target is 796 (and
there are five others: 829, 956, 961, 964, 991).
For 2, 4, 5, 8, 9, 10, the smallest is 807 (but there are 23 others)
Time to go to bed :)
--
Arnaud
PS: apolo
On Jan 21, 1:07 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> On Jan 20, 5:41 pm, [EMAIL PROTECTED] wrote:
>
> > Ever since I learnt to program I've always loved writing solvers for
> > the Countdown numbers game problem in different languages
>
> Ok so h
(100, 7, 'sub', 3, 'div', 1, 'sub', 9, 'add', 6, 'mul')
> (7, 3, 'mul', 6, 'sub', 9, 'mul', 1, 'sub', 100, 'add')
> (100, 7, 'mul', 6, 'sub', 1, 'sub', 9, 'add', 3, 'div')
> (100, 9, 'add', 7, 'add', 1, 'add', 3, 'div', 6, 'mul')
> (100, 9, 'sub', 7, 'div', 6, 'mul', 3, 'mul', 1, 'mul')
In countdown you are not required to use all numbers to reach the
target. This means you are missing solutions, e.g.
(1, 3, 6, 'mul', 'add', 7 , 'add', 9, 'mul')
After a quick glance at your code it seems to me that you can only
have solutions of the type:
(num, num, op, num, op, num, op, num, op, num, op)
this omits many possible solutions (see the one above).
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ant
> version (on my webpage linked to in the original post) takes about 15
> seconds. It seems to me like surely this problem can be more
> efficiently solved than that?
I haven't had the time to look at your solution yet. I wanted to have
a go without being influenced.
> Arnaud:
On Jan 21, 9:12 am, Terry Jones <[EMAIL PROTECTED]> wrote:
[...]
> Hi Arnaud.
Hi Terry
[...]
> WRT to the missing solution, note that my code only allowed multiplication
> by 1 if it was the last thing done. That was because you can multiply by 1
> at any time, and I didn
hes
> the KeyError.
If you really really want to write a grab function (IMHO pop is good
enough):
def grab(kw, key, default=None):
return kw.pop(key, default)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 21, 9:01 am, [EMAIL PROTECTED] wrote:
> Arnaud: I haven't had time to play with your solution yet - how quick
> does it run?
Ok I've done some quick timings, it's faster than I remembered it:
numbers = [2, 4, 5, 8, 25]
target = 758
Average time to find
(1) best
't know if
> that's the best approach. See my other post on this.
>
> Thanks
There's a very recent thread on this subject (topological sort)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
'//', '-+', '--']
def pretty(h):
"Print a readable form of a number's history"
if isinstance(h, int):
return str(h)
else:
x, op, y = h
x, y, xop, yop = pretty(x), pretty(y), getop(x), getop(y)
if xop + op in lbracket: x = "(%s)" % x
if op + yop in rbracket: y = "(%s)" % y
return ''.join((x, op, y))
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
; list(pairs(xrange(10)))
[(0, 1), (2, 3), (4, 5), (6, 7), (8, 9)]
>>> list(pairs('hello'))
[('h', 'e'), ('l', 'l')]
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
rom left to right,
so there is no risk that e.g. pairs4([1, 2, 3, 4]) returns [(2, 1),
(4, 3)].
Is there anything else that I am overlooking?
[1] http://docs.python.org/lib/itertools-functions.html
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
'import pairs; l=range(1000)')
print 'pairs%s: %s' % (i, t.timeit(1))
if __name__ == '__main__':
compare()
=
marigold:python arno$ python pairs.py
pairs1: 0.789824962616
pairs2: 4.08462786674
pairs3: 2.90438890457
pair
On Jan 22, 4:10 pm, Alan Isaac <[EMAIL PROTECTED]> wrote:
> http://bugs.python.org/issue1121416>
>
> fwiw,
> Alan Isaac
Thanks. So I guess I shouldn't take the code snippet I quoted as a
specification of izip but rather as an illustration.
--
Arnaud
--
http://mail.p
ought might justify leaving the routine alone, or
> optimising for readability instead.
But it's fun!
Some-of-us-can't-help-it'ly yours
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
time I'd love to hear your thoughts.
>
> Thanks.
>
> Jay
What you want is a dictionary:
albumInfo = {
'Rush': 'Rush', 'Fly By Night', 'Caress of Steel',
'2112', 'A Farewell to Kings', 'Hemispheres'],
'Enchant': ['A Blueprint of the World',
'Wounded', 'Time Lost'],
...
}
then to find the info just do:
>>> albumInfo['Enchant']
['A Blueprint of the World', 'Wounded', 'Time Lost']
It also makes it easy to add a new album on the fly:
>>> albumInfo["Lark's tongue in Aspic"] = [ ... ]
Hope that helps.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 22, 9:05 am, Terry Jones <[EMAIL PROTECTED]> wrote:
> Hi Arnaud
>
> > I've tried a completely different approach, that I imagine as 'folding'. I
> > thought it would improve performance over my previous effort but extremely
> > lim
On Jan 22, 10:56 pm, [EMAIL PROTECTED] wrote:
> Arnaud and Terry,
>
> Great solutions both of you! Much nicer than mine. I particularly like
> Arnaud's latest one based on folding because it's so neat and
> conceptually simple. For me, it's the closest so far to
On Jan 23, 3:45 pm, Terry Jones <[EMAIL PROTECTED]> wrote:
> Hi Arnaud and Dan
Hi Terry
> >>>>> "Arnaud" == Arnaud Delobelle <[EMAIL PROTECTED]> writes:
> >> What was wrong with the very fast(?) code you sent earlier?
>
> Arnaud>
On Jan 23, 7:06 pm, George Sakkis <[EMAIL PROTECTED]> wrote:
> The OP wanted an answer to a simple question, not a lecture on good
> software engineering principles.
I wholeheartedly agree.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 23, 8:40 pm, Terry Jones <[EMAIL PROTECTED]> wrote:
> >>>>> "Arnaud" == Arnaud Delobelle <[EMAIL PROTECTED]> writes:
>
> Arnaud> FWIW, I have a clear idea of what the space of solutions is, and
> Arnaud> which solutions I consider to be
ss A(object):
> @init
> def __init__(self): pass
This kind of approach can't work, you need to call super(A, obj).
super(type(obj), obj) is pointless, it defeats the whole purpose of
the mro!
The only way I can think of would be to create a metaclass, but I
don't think it
On Jan 23, 10:18 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
> 2008/1/23, Arnaud Delobelle <[EMAIL PROTECTED]>:
>
> > The only way I can think of would be to create a metaclass, but I
> > don't think it's worth it. super(A, obj).__init__(
On Jan 23, 11:51 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
Oops:
>
> class callsuper(object):
> def __init__(self, f):
> self.f = f
> def __get__(self, obj, cls=None):
> def newfunc(*args, **kwargs):
> super(self.cls, obj).__in
()): return ns[classname]()
...
>>> class A: pass
...
>>> mkobj('A')
<__main__.A instance at 0x6bd28>
>>>
But why do you want to do this?
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 24, 7:19 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
Oops again
>
> Change this line to:
> getattr(super.cls, obj), self.f.__name__)()
I mean
getattr(super(self.cls, obj), self.f.__name__)()
--
Arnaud
--
http://mail.python.org/mailman/
I can interface it with my little testing suite. Thanks for
posting it!
It was a lot of fun thinking about this, although I am sure that there
is a lot of room for improvement. In particular, there must be a
simple way to avoid the amount of list tinkering in fold(). Any
feedback greatly appr
hmark(posmax):
from time import clock
alist = [3]*1000 + [5] + [3]*1000
t = clock()
for _ in xrange(6000):
r = posmax(alist)
print posmax.__name__, round(clock() - t, 2), r
if __name__ == "__main__":
posmax_benchmark(clever_posmax)
posmax_benchmark(simple_posmax)
=
marigold:python arno$ python posmax.py
clever_posmax 3.25 1000
simple_posmax 0.95 1000
simple_posmax is more than 3x faster on my machine. It's not
surprising as even though the list is walked twice, it is all done in
C and no new objects have to be created. Then only non-C bit is when
the result of max(l) is fed to l.index().
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 27, 11:42 am, Paul Rubin <http://[EMAIL PROTECTED]> wrote:
> Arnaud Delobelle <[EMAIL PROTECTED]> writes:
> > def simple_posmax(l, key=None):
> > if key:
> > return l.index(max(l, key=key))
> > else:
> > return
On Jan 27, 11:32 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
[...]
>
> simple_posmax is more than 3x faster on my machine. It's not
> surprising as even though the list is walked twice, it is all done in
> C and no new objects have to be created. Then only non-C bit
gates well. Both u and v are one-
liners. I'm hoping for no funky line wrapping here.
Note: I'm not quoting the string as it makes no difference since they
evaluate to themselves:)
I'd like to know if anyone on the list has indulged in this time-
bending/mind-wasting activity before. If so, it would be nice to
create a list of such expressions.
Quining's-better-than-ironing'ly yours
--
Arnaud
[1] http://www.nyx.net/~gthompso/self_pyth.txt
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 27, 7:10 pm, [EMAIL PROTECTED] wrote:
> Hi all,
>
> As I understand it, the idea behind duck typing is that you just take
> an object and if it has the methods you want to use you use it
> assuming it to be the right type of object. I'm interested in
> extending this idea a bit, but I feel t
On Jan 27, 11:00 pm, "Russ P." <[EMAIL PROTECTED]> wrote:
> On Jan 27, 2:49 pm, "André" <[EMAIL PROTECTED]> wrote:
> > Perhaps this:http://www.python.org/dev/peps/pep-3107/mightbe
> > relevant?
> > André
>
> Thanks. If I read this correctly, this PEP is on track for Python 3.0.
> Wonderful!
Note t
On Jan 27, 4:14 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
[...]
> 1. Starting from the classic idea (lambda x:x%x)('lambda x:x%x') I got
> the following
> v=(lambda x:x%('"''""'+x+'"''""'))
On Jan 27, 11:58 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message
> Some years ago there was a substantial thread on this, (Shortest
> Self-Reproducing Programs, or some such) including a fairly long
ted
return decorator
class Test(object):
@autoassign('foo', 'bar')
def __init__(self, baz):
print 'baz =', baz
t = Test(foo=1, bar=2, baz=6)
# or Test(6, foo=1, bar=2)
print t.foo
print t.bar
print t.baz
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
got default values, type annotations
> (in Python3), *args and **kwargs, _ private names, and now we want to add
> auto-assignment.
Don't forget keyword only arguments! I find signatures too
complicated already, please let's not clutter them even more.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 28, 4:47 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Sun, 27 Jan 2008 23:51:28 -0200, Arnaud Delobelle
> <[EMAIL PROTECTED]> escribió:
>
> > Nice! I've got a slight variation without magic argument names:
>
> > class Test(objec
s why inspect may
be preferable
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
t', 'baz'):
try:
getattr(globals()[obj], attr)
except AttributeError:
print '%s.%s raises AttributeError' % (obj, attr)
output
baz = 5
baz = 6
1
2
8
3
10 11
5 102
w.foo raises AttributeError
w.bar raises AttributeError
t.baz raises AttributeError
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
57]
(list returned contains time taken to reach solution. By comparison
your code takes 0.264s on my machine. Mine is faster on this example,
but one example is not representative!)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 28, 4:31 pm, John Nagle <[EMAIL PROTECTED]> wrote:
> Arnaud Delobelle wrote:
[...]
> > Note that annotations do not provide explicit typing, AFAIK:
>
> > def f(x:int) -> int: return x*2
>
> > is stricly equivalent to
>
> > def f(x): return x*2
&
other area that was mentioned obliquely: preservation of
> docstrings (and other function attributes)
I think @wraps(...) does this (definitely copies __doc__).
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 29, 3:48 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
> | I found
> this:http://groups.google.com/group/comp.lang.python/browse_thread/thread/...
>
>
bject *item)
Append the object item at the end of list list. Return 0 if
successful; return -1 and set an exception if unsuccessful. Analogous
to list.append(item).
>
> }
>
> Can somebody give me a hint here, please? Passing simple arguments to and
> fro (e. g. single integer values) is no problem, but lists of unknown size?
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
de...
My code is quite naive and I suspect that combining your caching and
the tree pruning discussed in this thread would yield faster results.
Not sure if I'll have time to try this though...
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
g
array.array? Unless I am mistaken, these are just a thin wrapper
around normal C arrays. Anyway you could always convert your list
into a c array, do lots and lots of fast calculations, then convert it
back again to a list.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 29, 9:02 am, [EMAIL PROTECTED] wrote:
> If you've found an efficient way to walk through the possible
> solutions only once
As discussed earlier in this thread, the definition of 'only once' is
not as clear cut as one would first think (see Terry's thoughts on
t
ript(scriptname):
script = __import__(scriptname)
for obj in scriptobjs:
setattr(script, obj.__name__, obj)
return script
def playscript(script):
script.play()
===
Something like this. Obviously this is over simplified!
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
*_foo(PyObject *self, PyObject *args) {
> double *v;
> if (!PyArg_Parse(args, "(d)", &v))
> return NULL;
> to get a list as an array of doubles into 'v' (and back to Python)?
You can always iterate over the elements of the list an fill your c
array with the results. Look at the array_fromlist() function in
arraymodule.c, this function does exactly this.
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
for arg in args:
> ans = [x+[y] for x in ans for y in arg]
> return ans
While we're at it, a generator version:
def iproduct(head=None, *tail):
if head is None:
return ((),)
else:
return ((x,)+y for x in head for y in iproduct(*tail))
for a,
dex]
Or one could use the trick of counting from the right (untested):
n = len(a)
for i, x in enumerate(a):
if x == 99: del a[i-n]
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 30, 11:57 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> n = len(a)
> for i, x in enumerate(a):
> if x == 99: del a[i-n]
Oops. That can't work. Don't know what I was thinking here. I
probably did had one mental refactoring too many...
--
Arnaud
--
http:
ps.google.com/group/comp.lang.python/browse_thread/thread/290623baaa46e72a/
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
inside = {}
for x, i in sorted(bounds):
if inside.pop(i, None) is None:
for j, y in inside.iteritems():
if y != x: yield i, j
inside[i] = x
==
>>> list(overlaps(lst))
[(1, 2), (3, 0)]
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
t; 'H> %s' % M
Traceback (most recent call last):
File "", line 1, in
TypeError: not all arguments converted during string formatting
Pedantically yours,
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
class A(object):
... def _helper(x): return '<<%s>>' % x
... def __init__(self, msg, _helper=_helper):
... print _helper(msg)
... del _helper
...
>>> A('spam')
<>
<__main__.A object at 0x70170>
Confusingly yours,
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
for more information.
>>> {x*x for x in range(10)}
{0, 1, 4, 81, 64, 9, 16, 49, 25, 36}
>>> {x:x*x for x in range(10)}
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81}
>>>
That's nice.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
t; > prohibited. Please reply to the message immediately by informing the sender
> > that the message was misdirected. After replying, please erase it from your
> > computer system. Your assistance in correcting this error is appreciated.
>
> Could you now specifically apologize for all those question
> marks!!!
>
> :-)
>
> Peace, Paddy.
And for top-posting :)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Feb 1, 11:23 am, Thomas Pani <[EMAIL PROTECTED]> wrote:
> Arnaud Delobelle wrote:
>
> > This is definitely the best way:
>
> > from itertools import chain
>
> > def overlaps(lst):
> > bounds = chain(*(((x[1],i), (x[2], i)) for i,x in enumerate(lst)
On Feb 1, 1:28 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> Yours is O(n^2) and \Omega(n^2). I think mine is O(max(c, nlogn))
> (assuming constant time access for dictionaries, but 'inside' could be
> replaced with a list) where c is the number of overlaps. I
On Feb 1, 2:44 pm, "Neil Cerutti" <[EMAIL PROTECTED]> wrote:
> On Feb 1, 2008 8:28 AM, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
>
> > Yours is O(n^2) and \Omega(n^2). I think mine is O(max(c, nlogn))
> > (assuming constant time access for dictionaries,
strips.sort(cmp=strip_sort)
> for s in strips:
> node = s[2]
> if s[1] == 'L':
> clique.add(node)
> if s[1] == 'R':
> new_edges = [(node, i) for i in clique if i != node]
> edges += new_edges
>
On Feb 1, 8:34 pm, "Neil Cerutti" <[EMAIL PROTECTED]> wrote:
> On Feb 1, 2008 3:16 PM, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> > The total number of iterations is 1+2+...+n = n(n+1)/2 (when n is the
> > number of intervals) so this has quadratic behaviou
sets, then
- multiset(A).union(multiset(B)) == multiset(A.union(B))
- multiset(A).intersection(multiset(B)) == multiset(A.intersection(B))
(same for difference, symmetric_difference)
I think this is how I would like my multisets :)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Feb 2, 5:28 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Sat, 2008-02-02 at 01:17 -0800, Paul Rubin wrote:
> > Arnaud Delobelle <[EMAIL PROTECTED]> writes:
> > > * For sets {x, y} union {y, z} = {x, y, z}. The natural way of
> > > extending this to
301 - 400 of 1146 matches
Mail list logo