Mar-14-2021, 07:01 PM
Thanks a bunch, @bowlofred ! I was unsure of how to use for-loop in this case, but with your example I now know a real-world case for using them. Plus, now I've learned about Formatted string literals :-)
@snippsat Thanks, now my program is even more slim. All in all, my code is as below. Do you see anything I could improve in it to follow good practices? I do need to assign a value to response variable, but do I need to load the json into input_json and latter to input_json_keyfilter ?
Thanks again
@snippsat Thanks, now my program is even more slim. All in all, my code is as below. Do you see anything I could improve in it to follow good practices? I do need to assign a value to response variable, but do I need to load the json into input_json and latter to input_json_keyfilter ?
Thanks again
import requests response = requests.get('https://api.resrobot.se/v2/departureBoard?key=REDACTED') input_json = response.json() input_json_keyfilter = input_json.get("Departure") for line in input_json_keyfilter: print(f" {line['transportNumber']} -> {line['direction']}") print(f" {line['time']}")