python - 如何将循环的输出发送到 python 列表?

标签 python python-3.x list

我有这个代码

from opensky_api import OpenSkyApi

api = OpenSkyApi()
states = api.get_states(bbox=(51.3500, 51.5900, -0.6342, -0.2742))

for s in states.states:
    lat = s.latitude
    print(lat)

输出是这样的

51.4775
51.4589
51.4774
51.4774

如何使输出看起来像这样?

[51.4775, 51.4589, 51.4774, 51.4774]

最佳答案

lats = [s.latitude for s in states.states]
print(lats)

关于python - 如何将循环的输出发送到 python 列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50426378/

相关文章:

python-3.x - 从 python psycopg2 客户端连接到 Azure PostgreSQL 服务器

python-3.x - 无法启动 Qt uic

python - 我在 python 中创建列表列表时遇到问题

c# - 整数列表中的查找模式

python - 处理 Twisted 中的失败

python - Wide & Deep learning for large data 错误 : GraphDef cannot be larger than 2GB

python - 如何创建一个可以使用或不使用参数的装饰器?

python - 如何获取使用模式找到的数据列表

string - 字符 ' ' 处的字符串/字 rune 字中的词法错误?

python - 在 PIL 中换行