2345'] (string)
> to
> [1, 2, 3, 4, 5] [numbers]
Here's one way:
>>> map(int, '12345')
[1, 2, 3, 4, 5]
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
greg <[EMAIL PROTECTED]> writes:
> Arnaud Delobelle wrote:
>
>> What's a variable reference?
>
> It's a reference to a variable. It's what gets passed behind
> the scenes when you use a VAR parameter in Pascal, or a
> ByRef parameter in VB.
Do you m
e any object in Python) are
all instances of the object type, don't you?
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Terry Reedy <[EMAIL PROTECTED]> writes:
[...]
> A different version of what Arnaud D. said:
[...]
That was much clearer! I realise now that my explanation was an order
of magnitude too terse :)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
nonsense
> with that comparison function (i.e. it won't guarantee that things
> are sorted in increasing order)
Even in 2.x it doesn't work (I think I posted this earlier but I'm not
sure anymore) as this example shows:
2 < 3j and 3j < True, but True < 2
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
nction defined by Kay:
>> def comp(x1, x2):
>>try:
>>if x1>return -1
>>else:
>>return 1
>>except TypeError:
>>if str(x1)>return -1
>>else:
>>return 1
It just shows that it doesn't define an order for builtin types.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
None]
Using the key argument you don't have to do all this:
Python 3.0rc1+ (py3k:66521, Sep 21 2008, 07:58:29)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def none_firs
mething like:
>
> mylist.index('no*')
>
> Of course this doesn't work.
I have exactly what you need :)
>>> import fnmatch
>>> fnmatch.filter(['baba', 'nono', 'papa', 'mama', 'nostradamus'], 'no*')
['nono', 'nostradamus']
>>>
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ts
likely implementation and to hint that we can build one using the naive
concept of 'name for a thing' instead. IOW, 'call by value' is an
unnecessary obfuscation of what *actually* happens (even though it may
describe accurately the artifacts employed by an impl
; by defining values to be references
That's a neat and concise way of summarising this whole thread.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
al for one but it was rejected.
Nevertheless I think you can achieve this very easily.
In mymodule.py
--
def _test():
import doctest
import mymodule
doctest.testmod(mymodule)
That's it!
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ce Python code :)
Although you will acquire lots of clever-looking tricks.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ns.history.append(x)
print "Number of calls: %s\nHistory:%s" % (ns.ncalls, ns.history)
>>> foo(3)
Number of calls: 1
History:[3]
>>> foo(5)
Number of calls: 2
History:[3, 5]
>>> foo('spam')
Number of calls: 3
History:[3, 5, 'spam']
>>>
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
there are distinct values in it.
Here is a simpler solution.
from collections import defaultdict
def cluster(d):
clusters = defaultdict(list)
for key, val in d.iteritems():
clusters[val].append(key)
return clusters
Or without defaultdict:
def cluster(d):
clusters = {}
for key, val in d.iteritems():
clusters.setdefault(val, []).append(key)
return clusters
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Joe Strout <[EMAIL PROTECTED]> writes:
> On Nov 13, 2008, at 3:23 PM, Arnaud Delobelle wrote:
>
>> Aaron Brady <[EMAIL PROTECTED]> writes:
>>
>>> One way around it, which I like the idea of but I'll be honest, I've
>>> never used, is getti
Duck typing...
For a while I thought the word _duck_ was used in the sense of _dodge_.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
tion) I would import stuff at
the top of the module. I makes it clear what the module depends on.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
points
This is probably the MFAQ (Most FAQ)!
Have a look in http://www.python.org/doc/faq/ (I can't point at the
question as my internet pipes to the US are very rusty this morning)
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ion 'object value' is used in the Python
docs (and python.org is unreachable from where I am at the moment) but I
know that I don't need such a concept to understand, or code in, Python.
Objects have a type, may have attributes, and that's it!
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
r you know
that the two dictionaries have the same set of keys. If they do you can
simply write something like:
diff = [key for key, val1 in dic1.iteritems() if val1 != dic2[key]]
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
put also the matching inside the try? Or am I completely wrong?
In this case re.match has been designed to return None if there are no
matches so there is no need to look for exceptions. This is probably
because it is very common to use re.match(...) while expecting no match
so it is not really an 'exception'. Just do
m = re.match(...)
if m is None:
print 'error...'
else:
# Do something with m
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Scott David Daniels <[EMAIL PROTECTED]> writes:
> Arnaud Delobelle wrote:
>> Gilles Ganault <[EMAIL PROTECTED]> writes:
>>
>>> Hello
>>>
>>> I fill two dictionaries with the same number of keys, and then need to
>>> compare the value
f.v
...
>>> g = MyGenerator(5)
>>> for i in g:
... g.v = input("val:")
... print i
...
val:4
5
val:10
4
val:34
10
val:56
34
val:
Etc...
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Arnaud Delobelle <[EMAIL PROTECTED]> writes:
> Or to obtain a dictionary of differences:
>
> dict((k, (v, dic2[v]) for k, v in dic1.iteritems()
> if dic2[v] != v)
^
Should be k of c
you write
def foo(bar=[]):
bar.append(6)
...
you are describing what happens when you _call_ foo, i.e.:
1. if bar is not provided, make it equal to []
2. Append 6 to bar
3. ...
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
e would you want to know about it?
[...]
> If you like, you could think of the value of an object as the set of
> all possible values to which the object may evaluate in every possible
> context, given a particular state of the object.
This definition looks a bit circular to me ;)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
like to have a word with your maths teacher! There are plenty
of uses for 0, most of which are unrelated to 'nothingess'. E.g. 0 is
*greater* than -1 so it must be something.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
re you, I wouldn't inherit from list because it seems that your
list-like object quite different from a plain list.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Terry Reedy <[EMAIL PROTECTED]> writes:
> Mr.SpOOn wrote:
>> On Sun, Nov 16, 2008 at 7:15 PM, Arnaud Delobelle
>
>>> You should probably use the `bisect` module
>>> (http://docs.python.org/library/bisect.html) for searching and
>>> inserting into the l
[EMAIL PROTECTED] writes:
> I guess this goes a long way to explaining why the Python docs
> suck so badly in many areas.
I like the python docs very much.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ge him to learn more.
I know it's not based on Python but...
Do you know about scratch (http://scratch.mit.edu/)? I think it's a
fantastic tool for kids to learn to program. Unfortunately mine is
still too young but I am trying to introduce it in my school (I work as
a teacher).
--
A
ray[x12]=... = array[x20] = False
> ..
> ..
> array[x40]=array[x41]== array[x50] = False
It doesn't matter as none of this is valid Python. In Python you have to
write
array[x1] = False
array[x2] = False
Etc...
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Arnaud Delobelle <[EMAIL PROTECTED]> writes:
> jzakiya <[EMAIL PROTECTED]> writes:
>
>> I looked online and in books, but couldn't find a definitive answer to
>> this.
>>
>> I have an array and set multiple elements to either True or False at
>&
have looked it up instead of "translating" it from my
> mother tongue -- yes I ment "identity element". Sorry for the confusion.
>
Neutral element is correct. But maybe its use is limited to
mathematicians in the english-speaking word.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
usly like in the DSU pattern.
The implementation of python sort uses the DSU patterns.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
greg <[EMAIL PROTECTED]> writes:
> Arnaud Delobelle wrote:
>
>> Neutral element is correct. But maybe its use is limited to
>> mathematicians in the english-speaking word.
>
> I've only ever seen "identity element" in English mathematics.
>
and
correctly.
I think if I implemented an Interval class I would have it something
like this:
class Interval:
def __init__(self, left, right, closed_left=True, closed_right=True):
...
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Edwin <[EMAIL PROTECTED]> writes:
[...]
> a diary manager compatible with my Emacs diary file (sometimes I don't
> want to open Emacs for a quick note)
You mean that you sometimes don't have emacs open?
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
s are defined in baselib.py whereas types.py and special.py
import baselib, therefore you don't know how to make the factory
function aware of the types defined in special.py and types.py.
You can use cyclic import in many cases.
Or (better IMHO) you can make types register themselves with t
od(self):
> ... pass
> ...
>>>> example = Example()
>>>> example.method.im_self
> <__main__.Example object at 0x7fc3cdb5b650>
>>>> example.method.im_class
>
>>>> example.method.im_func
>
.im_self will become example.method.__self__ and in python 3. But I
can't see the equivalen of .im_class?
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
is supposed to be the way python works?
That's because Python isn't call-by-value. Or it is according to some,
it's just that the values it passes are references. Which, according to
others, is unnecessarily convoluted: it's call-by-object, or shall we
call it call-by-sharing? At least everybody agrees it's not
call-by-reference or call-by-name.
There. I hope this helps!
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
er and not self < other
cls.__gt__ = gt
# Do the same with __le__, __ge__
return cls
@totally_ordered
class Fraction:
def __init__(self, num, den=1):
assert den > 0, "denomintator must be > 0"
self.num = num
self.den = den
def __eq__(self, other):
return self.num*other.den == self.den*other.num
def __lt__(self, other):
return self.num*other.den < self.den*other.num
>>> q12=Fraction(1, 2)
>>> q23=Fraction(2, 3)
>>> q12 < q23
True
>>> q12 > q23
False
Granted it's not as efficient as a __cmp__ function.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
most pythonic approach to this.
Then it would be a good starting point to write some code. Then you
could post it and ask how it can be made more 'pythonic'.
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
rted(dictionary.keys()):
That would work only if the keys are sortable, and would be wasteful
because you would need to sort the keys for each value of i. A better
method may be to extract the keys before iterating over i:
keys = list(dictionary)
for i in 1, 10:
for key in keys:
...
Then you know that keys will be iterated over in the same order.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
if isinstance(data, list):
> return list.__new__( cls, data )
A list is mutable, its initialisation is done in __init__() not
__new__(). There was a recent post about this (in the last couple of
weeks).
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ortunately two threads seem to be intertwined: scroll down to when
the thread is renamed "python bug when subclassing list?".
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
s possible? If so, how?
Of course it's possible: use type(name, bases, dict).
>>> class A(object): pass
...
>>> class B(object): pass
...
>>> C = type('C', (A, B), {})
>>> issubclass(C, A)
True
>>> issubclass(C, B)
True
Call-by-object'ly yours
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ming tasks.
I'm only a very occasional user of vi, so I don't really know how vim
integrates with MacOS X but have you tried aquamacs
(http://aquamacs.org/)?
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> On Fri, 21 Nov 2008 17:26:21 +, Arnaud Delobelle wrote:
>
> [...]
>> As classes can be decorated in Python 3, you can write a decorator to
>> make a class totally ordered. Here is a very simplified proof of
>&
Steven D'Aprano <[EMAIL PROTECTED]> writes:
> On Sat, 22 Nov 2008 08:27:59 +, Arnaud Delobelle wrote:
>
>>>> Granted it's not as efficient as a __cmp__ function.
>>>
>>> What makes you say that? What do you mean by "efficient"? A
Arnaud Delobelle <[EMAIL PROTECTED]> writes:
> I haven't done any tests but as Fraction.__gt__ calls *both*
> Fraction.__eq__ and Fraction.__lt__ it is obvious that it is going to be
> roughly twice as slow.
There's a very simple way of emulating Fraction.
*intsets))
print "intersection: ", pretty(intersection(*intsets))
print "-"*20
--
Is this what you were looking for?
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Arnaud Delobelle wrote:
> [email protected] writes:
> [...]
> > I myself asked about how to write a library to efficiently do union
> > and intersection of sets containing time intervals some time ago on
> > this list and got little to no answers. It is a tricky
2005-07-16
Product D
2005-05-15 D
2005-07-21
Product V
2005-09-10 S & M
2005-10-11 M
2140-01-02
--
The date output is slightly different from yours - I didn't realise you
had time intervals an
[email protected] (Aahz) writes:
> Arnaud Delobelle wrote:
>>
>>There are no comments - I don't have the time to add any, sorry!
>
> The margin is too small to contain the proof?
I wish I could come up with such a resilient conjecture!
Ah but in this case, the p
7;add', 'mul', 'radd', 'rmul':
exec "def __%s__(*r): return List1(list.__%s__(*r))" % (op, op)
l1 = List1(range(10))
l2 = List1("Python rules")
I'll let you play with l1 and l2.
--
Arnaud
PS. What day is it again?
--
http://mail.python.org/mailman/listinfo/python-list
Carl Banks wrote:
> On Apr 1, 2:32 pm, Arnaud Delobelle wrote:
Check the date on the line above (and the PS in that post).
>
> If I were your boss and you ever pulled something like this, your ass
> would be so fired.
>
> This is unforgiveable, not only changing the ind
there is a bijection between S and S'. Obviously, finite
cardinals contain only one ordinal so finite cardinals can be
identified with their ordinal representative.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Neal Becker writes:
> How do I interleave 2 sequences into a single sequence?
Here's a way:
>>> a = [1,2,3,4]
>>> b = [5,6,7,8]
>>> [x for S in zip(a, b) for x in S]
[1, 5, 2, 6, 3, 7, 4, 8]
> How do I interleave N sequences into a single sequence?
ambda p, s=n**0.5: p<=s, P))
and not P.append(n),
count(2)
)
Of course there is no excuse for writing Python like that :)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ed in a list() call. Or you could take advantage of
iter(function, sentinel) which is little used:
>>> list(islice(iter(list, None), 10))
[[], [], [], [], [], [], [], [], [], []]
But none of these are very compelling.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
't timed it, but I would guess that the takewhile was faster
> only because the sqrt(n) had been factored out of the loop. Try the
> original loop again precalculating the sqrt(n) and see how that compares.
Most likely
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
orrect behavior.
>
>
> Another possible implementation:
>
> import operator,itertools
> def all(xs):
> return reduce(operator.and_, itertools.imap(bool, xs), True)
A contest! My entry:
def all(iterable):
return not sum(not x for x in iterable)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Tim Chase writes:
> Arnaud Delobelle wrote:
>> Paul Rubin <http://[email protected]> writes:
>>
>>> Tim Chase writes:
>>>>> Return True if all elements of the iterable are
>>>>> true. ...
>>>> Then I&
> Which of course is rubbish, extracting the sdqrt will have an effect but
> the main factor is that takewhile exits the loop as soon as the condition
> is false whereas a conditional in a generator comprehension doesn't stop
> the loop continuing to the end.
Absolut
Arnaud Delobelle writes:
> binops = ['add', 'sub', 'mul', 'div', 'radd', 'rsub'] # etc
> unops = ['neg', 'abs', invert'] # etc
Oops. There's a missing quote above. It should have been, of
return type(self)(int.__%s__(self))
"""
class MyInt(int):
for op in binops:
exec binop_meth % (op, op)
for op in unops:
exec unop_meth % (op, op)
del op
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
"andrew cooke" writes:
> Arnaud Delobelle wrote:
>> I do this:
>>
>> binops = ['add', 'sub', 'mul', 'div', 'radd', 'rsub'] # etc
>> unops = ['neg', 'abs', invert'] # etc
&
ad one
could describe all()'s behaviour as:
Return False as soon as the first false element in the iterable is
found. Otherwise return True when the iterable is exhausted.
Unfortunately it makes it much less obvious what the function is for and
the Python implementation is a clearer explanation IMHO.
So in the end, I think the doc reaches a good compromise: a short easy
to understand english description that gives a clear idea of what all()
is for, and a sample implementation for those who need/want the exact
behaviour.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ily when a variable has been rebound: it's on those
lines of the form
name = expression
Instead, make your 'changeValue" function return the new value, then
write:
import changeValue as c
arg = "old value"
arg = c.changeValue(arg)
print arg
It'll work, with the added benefit that it'll be clearer that arg was
changed.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
arno$ python -i uncert.py
>>> a = Value(2, 0.1)
>>> b = Value(7, 2)
>>> a+b
9.0 +- 2.0024984393742682
>>> a*b
14.0 +- 4.0607881007017825
>>> from math import *
>>> sin(a)
0.90929742682568171 +- 0.041615138303141563
>>> sin(2)
0.909297426825
[email protected] writes:
> Arnaud, your code is very interesting!
>
> On Apr 15, 1:00 pm, Arnaud Delobelle wrote:
>> I still don't understand why you need mutable floats.
>
> Here is why: the code that your proposed (or any code that does
> straightf
ame input!
I didn't see the simple:
>>> def all_same(l):
... return all(l[i]==l[i+1] for i in range(len(l)-1))
...
>>> all_same([1,2,3])
False
>>> all_same([1])
True
>>> all_same([1,1,1])
True
>>> all_same([1,1,1,2])
False
>>> all_same([])
True
>>>
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
> retlist = [func() for func in funclist]
And if you don't want to be Python 3 compliant:
retlist = map(apply, funclist)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
? ')",
... 60: "print 'Welcome,', name",
... 70: "gosub(80)"
... }
>>> run(program)
Hello, world 0
Hello, world 1
Hello, world 2
Hello, world 3
Hello, world 4
Hello, world 5
Hello, world 6
Hello, world 7
Hello, world 8
Hello, world 9
What is your name? Arnaud
Welcome, Arnaud
? Syntax error in line 70
OK.
>>>
As you can see, I haven't implemented gosub() yet.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
2.6, which means it will
> probably be gone in a few years:
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
without further sorting:
>>> [values[i] for i in indices]
[7, 5, 2, 1]
>>> [items[i] for i in indices]
['town', 'apple', 'car', 'phone']
This can be spelt:
>>> map(values.__getitem__, indices)
[7, 5, 2, 1]
>>> map(items.__getitem__, indices)
['town', 'apple', 'car', 'phone']
>>>
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
> in other words i want the list of random numbers to be arbitrarily
> different (which is why i am using rand()) but as different from other
> tuples in the list as possible.
>
> thank you for your help
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
nto a file for printing
>
> python -c 'import pylab; help(pylab)' > pylab.txt
Do you know pydoc?
>From the (shell) command line, try:
$ pydoc pylab # piped through less
$ pydoc pylab > pylab.txt # stored in a file
$ pydoc -w pylab # Creates a '
gt; def test_2(self):
> # time.sleep(1)
> module_data='''y=2'''
> write_module(module_data)
> imported=import_from_file(module_file_name)
My guess is that without the sleep(1), the imp.load_source function will
use the com
es,
e.g.
items = ['spam', 'eggs', 'wafer']
values = [3, 7, 3]
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
== d2
Thanks to the power of negative numbers, you only need one dict:
d = defaultdict(int)
for x in a:
d[x] += 1
for x in b:
d[x] -= 1
# a and b are equal if d[x]==0 for all x in d:
not any(d.itervalues())
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
new__(cls, mydata):
return ndarray.__new__(cls, 0)
def __init__(self, mydata):
self.mydata = mydata
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 24, 3:46 pm, Ole Streicher wrote:
> Arnaud Delobelle writes:
> > numpy.ndarray has a __new__ method (and no __init__). I guess this is
> > the one you should override. Try:
>
> What is the difference?
>
> best regards
>
> Ole
Here's an explanatio
thon, if you do:
a = [1, 2]
b = cons(0, a) # with your definition of cons
a[0] = 3
Then
a is now [3, 2]
b is now [0, 1, 2]
So in this respect, it is not accurate. But that's because Python lists
are vectors not conses.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
(not i for i in iterable) is not an optimisation of
all(iterable). Refer to [2]. Moreover, putting a list in parenthesis
does not magically turn it into a generator.
--
Arnaud
[1] http://www.python.org/dev/peps/pep-0289/
[2] http://docs.python.org/library/functions.html
--
http://mail.python.org/mailman/listinfo/python-list
ools import imap, izip
> return (len(a) == len(b)) and all(imap(comp, izip(a, b)))
Do you mean imap(comp, a, b)?
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
al_items(iter1, iter2, key=lambda x: x):
iter1, iter2 = iter(iter1), iter(iter2)
for x, y in izip(iter1, iter2):
if key(x) != key(y):
return False
for x, y in izip_longest(iter1, iter2):
return False
return True
(untested)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Arnaud Delobelle writes:
> Another way would be:
>
> def equal_items(iter1, iter2, key=lambda x: x):
> iter1, iter2 = iter(iter1), iter(iter2)
> for x, y in izip(iter1, iter2):
> if key(x) != key(y):
> return False
> for x, y in i
Peter Otten <[email protected]> writes:
> Arnaud Delobelle wrote:
>
>> def equal_items(iter1, iter2, key=lambda x: x):
>> iter1, iter2 = iter(iter1), iter(iter2)
>> for x, y in izip(iter1, iter2):
>> if key(x) != key(y):
>> re
AggieDan04 writes:
> Good suggestions. Another useful function I'd like to see in
> itertools is the Cartesian product. This can be implemented as:
[snip implementation]
You mean itertools.product?
http://docs.python.org/library/itertools.html#itertools.product
--
Arn
;
> [True]*20 + [False] + [True]*30
>
> But the generator expression produces worse performance with a shorter
> value_list:
>
> [True]*2 + [False] + [True]*3
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Telnet
>
>>>>
>
> Why do I see for
> telnetlib.Telnet, but I don't see the same for 'pexpect.spawn'>? Ie, how come I don't see 0xb7eded1c> ?
Because pexpect.spawn is a new-style class whereas telnetlib.Telnet is
an old-style class?
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
plementation:
>
> def xpairs(seq):
> len_seq = len(seq)
> for i, e1 in enumerate(seq):
> for j in xrange(i+1, len_seq):
> yield e1, seq[j]
>
Why not:
def xpairs(seq):
for i, el in enumerate(seq):
for j in xrange(i):
yield seq[j], el
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
r name in node_whitelist]
checker = SafetyChecker(node_whitelist, ['a', 'b', 'foo', 'bar'])
def safe_eval(expr, checker=checker):
t = ast.parse(expr, 'test.py', 'eval')
checker.visit(t)
return eval(expr)
Example:
>>> safe_eval('2*a - bar')
-4
>>> safe_eval('[1, 2] + [3, 4]')
[1, 2, 3, 4]
>>> safe_eval('f(foo)')
Traceback (most recent call last):
[...]
__main__.UnsafeError: unsafe node: Call
>>> safe_eval('x + 1')
Traceback (most recent call last):
[...]
__main__.UnsafeError: unsafe name: x
>>> safe_eval('lambda: x')
Traceback (most recent call last):
[...]
__main__.UnsafeError: unsafe node: Lambda
>>> safe_eval('foo or not foo')
'hello'
You'd have to tweak the node_whitelist using the info at
http://docs.python.org/library/ast.html#abstract-grammar
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ing a look at django
(http://djangoproject.com), a web framework that provides a lot of
functionality out of the box and easy integration with mysql (and other
database engines). It has good documentation and a good tutorial as
well. It has plenty of users and is actively developed.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
) for each element in x.
s = set(y)
z = [u for u in x if u not in s]
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
without interpreting the code via exec.
__import__
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
27;c': ['something'],
> 'd': ['something']}
>
> Why does ['something'] get attached to all columnMap elements instead
> of just element 'a'?
>
>
> In [58]: columnMap={'a': [], 'b': [],
7;DD']
>>>
Now you can look again.
(*) Pythonicity is often much debated as it lies for a good part in the
eye of the snake charmer. I don't think this snippet would generate
much debate!
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
601 - 700 of 1146 matches
Mail list logo