编写一个递归函数clean list(l1,l2),该列表将两个列表作为输入并返回l1中不存在的元素列表

时间:2018-10-30 17:32:45

标签: python-3.x

const base64 = require('base-64');
const JiraClient = require('jira-connector');

const jira = new JiraClient( {
host: 'ksr-ca-qmaltjira.ca.kronos.com',
protocol: 'http',
basic_auth: {
base64: base64.encode("username:password")
},
port: 8061

});

//endpoint
app.get('/jiraWIPCRs', (req, res) =>{

jira.search.search({
jql: ' "ECR #" != NULL AND "status" != Accepted AND "status" != Canceled AND 
"type" = "Change Request" AND "project"="Customer Support"',
maxResults: 5000
}, function(error, issue) {
res.send(issue);
});

});

const port = process.env.PORT || 2000;

app.listen(port, () => {
console.log("App is running on port " + port);
});

继续收到错误消息,指出+不支持的操作数类型:“ int”和“ function”

1 个答案:

答案 0 :(得分:0)

您的代码中有一些错误:

  1. 在基本情况下,您将返回一个int和一个函数,即return 0return clean_list
  2. 在第三种情况下,您需要串联列表,即串联并连接整数和一个列表l1[0] + clean_list(l1[1:], l2)
  3. 如果l1为空(not l1),则应返回空列表。

话虽如此,您在这里是代码:

def clean_list(l1, l2):
    if l1 == l2:
        return []

    if not l1:
        return []

    if l1[0] not in l2:
        return [l1[0]] + clean_list(l1[1:], l2)
    else:
        return clean_list(l1[1:], l2)


unique = clean_list([1, 2, 3, 4, 5, 6, 7], [2, 4, 6])
print(unique)

输出

[1, 3, 5, 7]