My confusion comes from the following piece of code:
memo = {1:1, 2:1}
def fib_memo(n):
global memo
if not n in memo:
memo[n] = fib_memo(n-1) + fib_memo(n-2)
return memo[n]
I used to think that the time complexity for this code is O(n) due to its
use of memoization.
However, I was told recently
n message
news:[EMAIL PROTECTED]
> Ruan schreef:
> > My confusion comes from the following piece of code:
> >
> > memo = {1:1, 2:1}
> > def fib_memo(n):
> > global memo
> > if not n in memo:
> > memo[n] = fib_memo(n-1) + fib_memo(n-2)
> > return memo[n]
&g
Can't range go from larger to smaller?
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Dongsheng Ruan wrote:
>
>> I want to turn an Array into a heap, but my code just doesn't work: no
>> change after ex
I found out what is wrong.
You must give it a negative step, like range(10,1,-1)
But my code is not good enought for heapify.
I will try again.
"Ruan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Can't range go from larger to smaller?
>
>
On 2018-04-15 13:31, Kirill Balunov wrote:
>
>
> 2018-04-15 10:58 GMT+03:00 Yubin Ruan :
>
> [this is a bit late...]
>
> Did you really have any benchmark for it? I know what you are doing but it
> seems to be a pre-mature optimization. If this really is the
;ccc","ddd","eee"]
How can I write a regex to match that?
I have try to use the **positive lookbehind assertion** in python regex,
but it does not allowed variable length of lookbehind.
Thanks in advance,
Ruan
--
https://mail.python.org/mailman/listinfo/python-list
On Wednesday, June 15, 2016 at 12:18:31 PM UTC+8, Lawrence D’Oliveiro wrote:
> On Wednesday, June 15, 2016 at 3:28:37 PM UTC+12, Yubin Ruan wrote:
>
> > I want to match the all the text surrounded by those " ",
>
> You are trying to use regex (type 3 grammar) t
g to make
it a **online** string. You don't have to show code in that respect.
Thanks in advance!
Ruan.
--
https://mail.python.org/mailman/listinfo/python-list
ython write to file using unicode(type 'str')? Does python
encode 'str'(Unicode) automatically before writing things to file? If it's
true, then why can't it do that automatic encoding when I trying to write a
'str' to socket ?
Regards,
Ruan
--
https://mail.python.org/mailman/listinfo/python-list
with a cell class like this:
#!/usr/bin/python
import sys
class Cell:
def __init__( self, data, next=None ):
self.data = data
self.next = next
def __str__( self ):
return str( self.data )
def echo( self ):
print self.__str__()
--
http://mail.python.org/mailman/listinfo/python-l
list in Python.
"Gary Herron" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Dongsheng Ruan wrote:
>> with a cell class like this:
>>
>> #!/usr/bin/python
>>
>> import sys
>>
>> class Cell:
>>
>> def
Hi
Does anybody know how to pass multiple arguments to the function
tested in timeit.timer() in
python?
I googled and found how to pass one argument:
x=1
mytime = timeit.Timer( setup="from Createlst import createlst", stmt=
"createlst(%s)"%(x) )
But how can I extend it to two or more
I remember that in python there is some kind of dummy statement that just
holds space and does nothing.
I want it to hold the place after a something like if a>b: do nothing
I can't just leave the space blank after if statement because there will be
error message.
Does anybody know what to ins
Yes, that's just what I want.
Thanks!
- Original Message -
From: Analog Kid
To: Dongsheng Ruan
Cc: python-list@python.org
Sent: Wednesday, January 31, 2007 12:04 PM
Subject: Re: What is the dummy statement that do nothing in Python?
hey dongsheng:
not too sure
Not quite related with Python. But my Data Structure course is experiemented
on python and there is no data structure group, So I have to post here:
Write a procedure (in pseudocode!) to increase the number of buckets in a
(closed) hash table. Analyze its time and space complexity.
--
http:/
TED]> wrote in message
news:[EMAIL PROTECTED]
> Ruan schreef:
>> "Roel Schroeven" <[EMAIL PROTECTED]> wrote:
>>> Ruan schreef:
>>>> My confusion comes from the following piece of code:
>>>>
>>>> memo = {1:1, 2:1}
>
This seems to be clever to use reference for list.
Is it unique to Python?
How about the traditional programming languages like C, Pascal or C++?
"Roel Schroeven" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Dongsheng Ruan schreef:
>> "Roe
I got feed back saying" list object is not callable". But I can't figure out
what is wrong with my code.
A=[3,5,4,9,6,7]
l=len(A)-1
for i in range(l):
print A(i)
--
http://mail.python.org/mailman/listinfo/python-list
I want to turn an Array into a heap, but my code just doesn't work: no
change after execution.
A=[3,5,4,9,6,7]
m=len(A)-1
for i in range(m,1):
t=(i-1)/2
if A[i]>A[t]:
A[i],A[t]=A[t],A[i]
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, Jun 05, 2017 at 05:16:55PM +0200, Maria Alonso-Martirena wrote:
> Good morning,
>
>
>
> You asked me to subscribe before writing to you and i've already done so. I
> need your help: I’ve just downloaded Python for Windows (versión 3.6.1.).
> However, when I try to open it, it just says “
20 matches
Mail list logo