dictionary - How to get a Ordereddictionary element with lowest value, which is also greater than a certian threshold, in python? -
right doing key lowest value in ordered dict
hunting_targets = ordereddict() element in data["hunting_targets"]: hunting_targets[data["hunting_targets"][element]["user_id"]]=data["hunting_targets"]element]["gold"] hunting_targets=ordereddict(sorted(hunting_targets.items(), key=lambda t: t[1],reverse= false)) hunting_target = next(iter(hunting_targets))
i repeat lastly step until value greater threshold.
but there more efficient way isn't there ? more efficient way of doing this?
edit: key , id of type int. , value int too
without knowing exact arrangement of info (i.e. keys , values of data
, hunting_targets
, etc.), it's hard certain. may see performance improvements using heapq
in fashion. heapq algorithm designed maintain smallest element of collection readily available.
python dictionary
No comments:
Post a Comment