小编Emi*_*zar的帖子

将函数放在类方法中是一种糟糕的编程习惯吗?

我正在看这样一个案例:

def parse_item(self, response):

    item = MetrocItem()

    def ver(string):
        if string:
            return string
        else:
            return 'null'

    item['latitude'] = ver(response.xpath('//input[@id="latitude"]/@value').extract_first())
Run Code Online (Sandbox Code Playgroud)

它有效,但有没有更好的方法来做到这一点?

python oop

5
推荐指数
1
解决办法
1141
查看次数

Julia 中的合并排序实现

我正在尝试在 Julia 中实现合并排序算法,但我似乎无法理解该算法所需的递归步骤。我的代码如下:

\n
m\xe2\x82\x90 = [1, 10, 7, 4, 3, 6, 8, 2, 9]\n\nb\xe2\x82\x81(t, z, half\xe2\x82\x81, half\xe2\x82\x82)= ((t<=length(half\xe2\x82\x81)) && (z<=length(half\xe2\x82\x82))) && (half\xe2\x82\x81[t]<half\xe2\x82\x82[z])\nb\xe2\x82\x82(t, z, half\xe2\x82\x81, half\xe2\x82\x82)= ((z<=length(half\xe2\x82\x82)) && (t<=length(half\xe2\x82\x81)) ) && (half\xe2\x82\x81[t]>half\xe2\x82\x82[z])\n\nfunction Merge(m\xe2\x82\x81, m\xe2\x82\x82)\n    N = length(m\xe2\x82\x81) + length(m\xe2\x82\x82)\n    B = zeros(N)\n\n    i = 1\n    j = 1\n\n    for k in 1:N\n        if b\xe2\x82\x81(i, j, m\xe2\x82\x81, m\xe2\x82\x82)\n            B[k] =  m\xe2\x82\x81[i]\n            i += 1 \n        elseif b\xe2\x82\x82(i, j, m\xe2\x82\x81, m\xe2\x82\x82)\n            B[k] =  m\xe2\x82\x82[j]\n            j += 1\n        elseif j >= length(m\xe2\x82\x82)\n            B[k] …
Run Code Online (Sandbox Code Playgroud)

algorithm julia

5
推荐指数
1
解决办法
203
查看次数

标签 统计

algorithm ×1

julia ×1

oop ×1

python ×1