简体   繁体   English

用Python编写此循环的方式是什么?

[英]What is the Pythonic way to write this loop?

for jr in json_reports:
  jr['time_created'] = str(jr['time_created'])

在我看来你已经在那儿了

That would be the pythonic way to write the loop if you need to assign it to the same list. 如果需要将循环分配给相同的列表,那将是编写循环的Python方法。

If you just want to pull out strings of all time_created indices in each element of json_reports , you can use a list comprehension: 如果你只是想退出时,所有的字符串time_created指数中的每一个元素json_reports ,您可以使用列表理解:

strings = [str(i['time_created']) for i in json_reports]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM