python - 从列表中提取确切的值
问题描述
我怎样才能从中提取经度和纬度 -
Feature(place='夏威夷火山 SSE 12km', long=-155.2005, lat=19.3258333, depth=6.97, mag=5.54)
部分代码如下
lrgst = features[0]
print ('\n',lrgst)
plt.bar(y_pos, magn)
plt.xticks(y_pos, loc)
plt.ylabel('Magnitude')
plt.show()
features = list(get_info()) #Storing our json information into a list 'Features'
解决方案
假设“功能”是给出示例的条目列表,则此解决方案将起作用:
features = ["Feature(place='12km SSE of Volcano, Hawaii', long=-155.2005, lat=19.3258333, depth=6.97, mag=5.54)"]
def find(string, char_before, char_after):
start = string.find(char_before) + len(char_before)
end = string[start:].find(char_after) + start
return string[start:end]
long = find(features[0], 'long=', ', ')
lat = find(features[0], 'lat=', ', ')
print(lat + ', ' + long)
19.3258333, -155.2005
推荐阅读
- microsoft-graph-api - 不支持endsWith过滤器?
- vba - SAP GUI 脚本 VBA - 按钮按下被忽略
- c++ - C++中MCU寄存器映射的位域联合
- html - 我的网站内容在页脚下方
- java - Java Deque(从子数组中查找唯一整数的最大数量。)
- java - 添加项目后防止Jface向导列表调整窗口大小
- javascript - 通过 JQuery Ajax 发送授权令牌承载 - 后端是 .NET Core Web Api
- bash - Bash:从 grep 等待的非并行 FOR 循环执行
- apache-spark - 使用 Spark BigQueryConnector 读取 Big Query
- python-3.x - 无法为使用 PEP 517 且无法直接安装的 numpy 构建轮子