需要帮助理解python代码 [英] Need help in understanding a python code

查看:115
本文介绍了需要帮助理解python代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想了解以下内容:

#a是一个整数数组


max([(sum(a [j:i]),(j,i))


你能告诉我这是什么意思吗,

我认为总和(a [j:i]意味着找到一些从[j]到[i]

但是部分(j,i)的含义是什么?

Hi,

I am trying to understand the following line:
# a is an integer array

max([(sum(a[j:i]), (j,i))

Can you please tell me what that means,
I think sum(a[j:i] means find the some from a[j] to a[i]
But what is the meaning of the part (j,i)?

推荐答案

2008年11月15日星期六晚上8:41, si *************** @ gmail.com

< si * **************@gmail.com写道:
On Sat, Nov 15, 2008 at 8:41 PM, si***************@gmail.com
<si***************@gmail.comwrote:




我我试图理解以下几行:

#a是一个整数数组


max([(sum(a [j:i]),(j ,i))
Hi,

I am trying to understand the following line:
# a is an integer array

max([(sum(a[j:i]), (j,i))



此代码无效。您有[没有关闭]。


干杯,

克里斯

-

沿着鬣蜥的路径......
http://rebertia.com


>

能告诉我这意味着什么,

我认为总和(a [j:i]意味着找到一些从[j]到[i]

但这部分是什么意思(j, i)?


-
http://mail.python.org/mailman/listinfo/python-list


11月16日,3日:41 * pm,silverburgh.me ... @ gmail.com

< silverburgh.me ... @ gmail.comwrote:
On Nov 16, 3:41*pm, "silverburgh.me...@gmail.com"
<silverburgh.me...@gmail.comwrote:




我想了解以下内容:

#a是一个整数数组


max([(sum(a [j:i]),(j,i))


能告诉我这是什么意思吗,

我认为总和(a [j:i]意味着从[j]到[i]

找到一些但是部分(j,i)的含义是什么?
Hi,

I am trying to understand the following line:
# a is an integer array

max([(sum(a[j:i]), (j,i))

Can you please tell me what that means,
I think sum(a[j:i] means find the some from a[j] to a[i]
But what is the meaning of the part (j,i)?



0." integer array"在Python中是一个非常宽松的术语。幸运的是,

回答你的问题不受此影响。

1.对不起,max ...行语法不正确;有两个

[s且只有一个];有4(s和3)s。尝试复制行

并粘贴,而不是重新输入。

2.我不打算猜测如何修复括号不匹配。

3.请注意,您已从关于总和的问题中删除了a) ......

它可能应该是总和([j:i])。

4.这是一个[不是一些!!) j]到[i-1]包括两者。

这是Python中用于表示范围结束的标准习语

作为第一个未使用的元素。

5.即使在修复了支架不匹配之后,看起来你将会有一个表达式被丢弃的表达式。也许您可能希望



利息之前和之后给我们几行背景。

0. "integer array" is a very loose term in Python. Fortunately the
answer to your question is not affected by that.
1. Sorry, the max... line is not syntactically correct; there are two
[s and only one ]; there are 4 (s and only 3 )s. Try copying the line
and pasting, not re-typing.
2. I''m not going to try to guess how to fix the bracket mismatches.
3. Note that you have left off a ) from your question about "sum" ...
it probably should be sum([j:i]).
4. That is the sum (not "some"!!) of a[j] to a[i-1] both inclusive.
It''s a standard idiom in Python for the end of a range to be expressed
as the first unused element.
5. Even after fixing the bracket mismatches, it looks like you will
have an expression whose value is thrown away. Perhaps you might like
to give us a few lines of context before and after the line of
interest.


这是完整的源代码:

def A(w,v,i,j):

如果i == 0或j == 0:返回0

如果w [i-1] j:返回A(w,v,i-1,j)

如果w [i-1]< = j:return max(A(w,v,i-1,j),v [i-1] + A(w,v,i-1,j-w [i-1]))


我正在读这个博客

http://20bits.com/articles/introduct...c-programming/

2008年11月15日星期六晚上10:54,Chris Rebert< cl *@rebertia.comwrote:
This is the full source code:
def A(w, v, i,j):
if i == 0 or j == 0: return 0
if w[i-1] j: return A(w, v, i-1, j)
if w[i-1] <= j: return max(A(w,v, i-1, j), v[i-1] + A(w,v, i-1, j - w[i-1]))

I am reading this blog

http://20bits.com/articles/introduct...c-programming/
On Sat, Nov 15, 2008 at 10:54 PM, Chris Rebert <cl*@rebertia.comwrote:

2008年11月15日星期六晚上8:41, si *************** @ gmail.com

< si * **************@gmail.com写道:
On Sat, Nov 15, 2008 at 8:41 PM, si***************@gmail.com
<si***************@gmail.comwrote:

>

我正在尝试理解以下行:
#a是一个整数数组

max([(sum(a [j:i]),(j,i))
>Hi,

I am trying to understand the following line:
# a is an integer array

max([(sum(a[j:i]), (j,i))



此代码无效。你有一个[没有关闭]。


干杯,

克里斯

-

沿着鬣蜥的路径......
http://rebertia.com


>>
你能告诉我这是什么意思吗,
我认为总和(a [j:i]意味着找到一些来自a [j]到a [i]
但是(j,i)部分是什么意思?

-
http://mail.python.org/mailman/listinfo/python-list


这篇关于需要帮助理解python代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆