prov_code = ['130100000000', '石家庄市', '130200000000', '唐山市', '130300000000', '秦皇岛市', '130400000000',
'邯郸市',
'130500000000', '邢台市', '130600000000', '保定市', '130700000000', '张家口市', '130800000000',
'承德市',
'130900000000', '沧州市', '131000000000', '廊坊市', '131100000000', '衡水市', '133100000000',
'雄安新区']
urls = ['http://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/13/1301.html',
'http://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/13/1302.html',
'http://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/13/1303.html',
'http://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/13/1304.html',
'http://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/13/1305.html',
'http://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/13/1306.html',
'http://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/13/1307.html',
'http://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/13/1308.html',
'http://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/13/1309.html',
'http://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/13/1310.html',
'http://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/13/1311.html',
'http://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/13/1311.html'
]
使用切片
# 城市列表
list_city = []
for i in range(0,len(prov_code),2):
list_city.append(prov_code[i:i+2])
print(list_city)
二、将列表中城市对应地址列表,再添加到一个新列表中
使用zip()函数
# ②新的序列的长度以参数中最短的序列为准.
lls=[]
for pr,url in zip(list_city,urls):
pr.append(url) #追加url路径
print(pr)
lls.append(pr) #添加到列表
print(lls)