Thanks all for the feedback. As you all rightly pointed out, I was
confusing myself by not keeping a track of the recursion depth.
Thanks again
2009/7/3 Alan Gauld :
>
> "karma" wrote
>
>> thinking that a recursive solution would work here, but so far I can't
&g
Hi all ,
I have a nested list in the structure
[root,[leftSubtree],[RightSubtree]] that I want to print out. I was
thinking that a recursive solution would work here, but so far I can't
quite get it working. This is what I have so far:
Can someone suggest whether this is suited to a recursive sol
/recipes/52560/
>
> Robert
>
>
> On Thu, 2009-06-18 at 15:15 +0200, karma wrote:
>> I was playing around with eliminating duplicates in a list not using
>> groupby. From the two solutions below, which is more "pythonic".
>> Alternative solutions would be
I was playing around with eliminating duplicates in a list not using
groupby. From the two solutions below, which is more "pythonic".
Alternative solutions would be welcome.
Thanks
x=[1,1,1,3,2,2,2,2,4,4]
[v for i,v in enumerate(x) if x[i]!=x[i-1] or i==0]
[x[i] for i in range(len(x)-1) if i==0
Excellent, thanks for that answer Kent. Also thanks for the link
2009/6/18 Kent Johnson :
> On Thu, Jun 18, 2009 at 6:21 AM, karma wrote:
>> Hi All,
>>
>> I'm trying to write a function that flattens a list. However after I
>> call the function more than once, it
Hi All,
I'm trying to write a function that flattens a list. However after I
call the function more than once, it appends the result (a list) from
the second call with the first. I can get around it by either setting
the list to an empty one before calling the function, but I would like
to keep it
Hi Raj,
I'm another learner, I used the following:
>>> def toss(n):
heads = 0
for i in range(n):
heads += random.randint(0,1)
return heads, n-heads
>>> print "%d heads, %d tails" % toss(100)
Best of luck in your python endeavors!
2009/6/10 Raj Medhekar :