mercredi 30 septembre 2020

Break out of two loops and two if statements - Python [duplicate]

I have a section of code used to find a key value within a dictionary. The current method i'm using works, however i'm attempting to speed up the execution of the script.

To do this i want to move the if ticker in tick: to immediately after for tick in trades_dic["Ticker"].items():. The intention of which is to speed up this element by removing the need to check all combinations.

Full section of code below, any help would be much appreciated. :)

    for tick in trades_dic["Ticker"].items():
        for stat in trades_dic["Status"].items():
            if ticker in tick and "Open" in stat:
                (tick_k, tick_val) = tick
                (stat_k, stat_val) = stat
                if tick_k == stat_k:
                    (active_k, v) = tick
                    break
        else:
            continue
        break

Aucun commentaire:

Enregistrer un commentaire