python使用列表按照一定格式批量输出,配合地图热力图程序“食用”更佳哦~
import re
import random
posi = [
'113.936539169252,22.5385001957843',
'126.541615090316,45.8088258279521',
'126.675638499523,45.7658661637579',
'125.296653763226,43.8524275671504',
'125.295401255854,43.8406414749619',
'125.330602075906,43.8219535010431',
'123.465461035375,41.8022741388046',
'123.471096644822,41.6838300691906',
]
count = [
'549',
'36',
'243',
'713',
'697',
'97',
'883',
'59'
]
listlng = []
listlat = []
for i in posi:
lng = i.split(',')[0]
lat = i.split(',')[-1]
listlng.append(lng)
listlat.append(lat)
#print(listlng)
for j in range(0,len(posi)):
# print(listlng[j],listlat[j],count[j])
#count = random.randrange(0, 101)
print('{"count": %s, "lat": %s, "lng":%s},' %(count[j],listlat[j],listlng[j]))
运行结果:
{"count": 549, "lat": 22.5385001957843, "lng":113.936539169252},
{"count": 36, "lat": 45.8088258279521, "lng":126.541615090316},
{"count": 243, "lat": 45.7658661637579, "lng":126.675638499523},
{"count": 713, "lat": 43.8524275671504, "lng":125.296653763226},
{"count": 697, "lat": 43.8406414749619, "lng":125.295401255854},
{"count": 97, "lat": 43.8219535010431, "lng":125.330602075906},
{"count": 883, "lat": 41.8022741388046, "lng":123.465461035375},
{"count": 59, "lat": 41.6838300691906, "lng":123.471096644822},
来源:CSDN
作者:HelenLee01
链接:https://blog.csdn.net/weixin_43289135/article/details/104651220