我在列表中有 id 列表,如下所示:[[1347,1805371369,1805371401,1805371409,1805371424,1805371434,1805371462],[1805371691,1805371699,1805371712,1805371715,1805371725,1805371742,1917952665]']我试图将它们合并到一个列表中,如下所示:[1347,1805371369,1805371401,1805371409,1805371424,1805371434,1805371462,1805371691,1805371699,1805371712,1805371715,1805371725,1805371742,1917952665' ]但我的结果变成了这样,我不知道为什么:['1','3','4','7',',','1','8','0','5','3','7','1','3','6','9'.......']']我尝试过 itertools 、 flat 和 using for 循环的方法,但它们都给了我同样的东西,所以我认为 list 本身有问题,但我不确定是什么。请帮忙import itertools r=[[1347,1805371369,1805371401,1805371409,1805371424,1805371434,1805371462],[1805371691,1805371699,1805371712,1805371715,1805371725,1805371742,1917952665]]merged = list(itertools.chain(*r))print(merged)实际代码:import requestsimport jsonfrom datetime import datetimefrom datetime import timedeltaimport itertoolsurl='https://www.example.com/api/rest/1.1/etl/surveyresponses/ids/'headers = {'Content-Type': "application/x-www-form- urlencoded",'Authorization': "Bearer ******-****-****-****-*********"}start_date = "2016-01-01"stop_date = "2016-01-08"endDate = "2016-02-014"orgid='****'r=[]#Can only call 7 days at once, need to call the API multiple time and combine the result together for another API call while stop_date < endDate: start = datetime.strptime(start_date, "%Y-%m-%d") + timedelta(days=7) stop = datetime.strptime(stop_date, "%Y-%m-%d") + timedelta(days=7) start_date=start.strftime('%Y-%m-%d') stop_date=stop.strftime('%Y-%m-%d') if stop_date>datetime.today().strftime('%Y-%m-%d'): stop_date = datetime.today().strftime('%Y-%m-%d') req_url=url+start_date+'/'+stop_date+'/'+orgid result =requests.get(req_url, headers=headers) r.append(result.text)merged = list(itertools.chain(*r))
添加回答
举报
0/150
提交
取消