> If you're getting this via the mailing list, just hit Reply, and then
>
> change the To: address to python-list@python.org - that's the simplest
>
> (assuming you don't have a Reply To List feature, but you wouldn't be
>
> saying the above if you had one). That way, you get a citation line,
>
On Thursday, June 20, 2013 12:45:27 PM UTC+2, Antoon Pardon wrote:
> Op 19-06-13 18:14, russ.po...@gmail.com schreef:
>
> >
>
> all(map(lambda x: bool(x), xrange(10**9)))
>
>
>
> Since you already have your answer, I just like to get your attention
>
> to the fact the the lambda is super
On Thursday, June 27, 2013 6:19:18 AM UTC+2, Thrinaxodon wrote:
> =
>
> >MESSAGE FROM COMPUTER GEEK.
>
> =
>
> >
>
> THRINAXODON HAS RECENTLY RECEIVED THIS MESSAGE FROM THE PYTHON FOUNDER:
>
>
>
> Oh my God! It's hard to program with, it`s troubling for so m
The type() builtin according to python docs, returns a "type object".
http://docs.python.org/2/library/types.html
And in this module is bunch of what I assume are "type objects". Is this
correct?
http://docs.python.org/2/library/functions.html#type
And type(), aside from being used in as an alte
On Sunday, June 30, 2013 8:06:35 AM UTC+2, Chris Angelico wrote:
> There's a bit of a discussion on python-ideas that includes a function
>
> that raises StopIteration. It inspired me to do something stupid, just
>
> to see how easily I could do it...
>
>
>
> On Sun, Jun 30, 2013 at 3:45 PM, N
I know this is simple but I've been starring at it for half an hour and trying
all sorts of things in the interpreter but I just can't see where it's wrong.
def supersum(sequence, start=0):
result = start
for item in sequence:
try:
result += supersum(item, start)
Nevermind!
Stupid of me to forget that lists or mutable so result and start both point to
the same list.
--
http://mail.python.org/mailman/listinfo/python-list
Since I've already wasted a thread I might as well...
Does this serve as an acceptable solution?
def supersum(sequence, start=0):
result = type(start)()
for item in sequence:
try:
result += supersum(item, start)
except:
result += item
return res
I read through all of the posts and thanks for helping. What was supposed to be
simple a (recursively) straightforward, turned out to be quite tricky.
I've set up a small testing bench and tried all of the proposed solutions
including my own but none pass. I'll post it below.
I've also discover
I got it! One of the testcases was wrong,
([[1], [1]],[1],[1, 1]),
should be
([[1], [1]],[1],[1, 1, 1]),
And the working solution.
def supersum(sequence, start=0):
result = start
start = type(start)()
for item in sequence:
try:
Sorry for the vague title. Probably best to just show you the code that
explains it better.
This is a simplified example of what I want to do:
# THIS DOESN'T WORK
from random import choice
class Expr(object):
"""
Expr(expr, op, val) -> an expression object.
"""
def __init__(se
I didn't do a good job of explaining it cos I didn't want it to be a TLDR; but
I could've added a little more. To clarify:
Expr is just a way to represent simple arithmetic expressions for a calculator.
Because the expression has to be modified and built over time, and evaluated
from left to ri
On Wednesday, July 10, 2013 12:20:47 AM UTC+2, Ian wrote:
> On Tue, Jul 9, 2013 at 4:18 PM, Ian Kelly wrote:
>
> > If you actually want to modify the current object, you would need to
>
> > do something like:
>
> >
>
> > def expand(self):
>
> > import copy
>
> > self.expr
On Wednesday, July 10, 2013 9:33:25 PM UTC+2, Terry Reedy wrote:
> On 7/10/2013 4:58 AM, Russel Walker wrote:
>
>
>
> > There is the name x and the class instance (the object) which exists
>
> > somewhere in memory that x points to. self is just another name tha
I've been mucking around with this silly class pretty much the whole day and my
eyes are about closing now so this is the solution for now I think. Please feel
free to drop any suggestions. I think I mostly just ended up shaving off allot
of extraneous responsibility for the class, that and inhe
...oh and here is the class I made for it.
class xslice(object):
'''
xslice(seq, start, stop, step) -> generator slice
'''
def __init__(self, seq, *stop):
if len(stop) > 3:
raise TypeError("xslice takes at most 4 arguments")
elif len(stop) < 0:
Just some dribble, nothing major.
I like using slices but I also noticed that a slice expression returns a new
sequence.
I sometimes find myself using them in a for loop like this:
seq = range(10)
for even in seq[::2]:
print even
(That's just for an example) But wouldn't it be a bit of a
> > def __init__(self, seq, *stop):
>
>
>
> Wouldn't it be better if it has the same signature(s) as itertools.islice?
That's actually what I was going for, except I was modeling it after range, but
that was the only way I knew to implement it.
> > if len(stop) > 3:
>
> >
18 matches
Mail list logo