example from chapter 8. Greedy algorithms. Essence - enumerates all the sets. finds intersection. I can not understand how final_station.add (best_station) works? when the interpreter is started, there is always a different answer. If instead of add I write append and remove set. all OK.
states_needed=set(["mt","wa","or","id","nv","ut","ca","az"]) stations ={} stations["kone"]=set(["id","nv","ut"]) stations["ktwo"]=set(["id","wa","mt"]) stations["kthree"]=set(["or","nv","ca"]) stations["kfour"]=set(["nv","ut"]) stations["kfive"]=set(["ca","az"]) final_station=set() while states_needed: best_station=None state_covered=set() for station,state in stations.items(): covered=states_needed & state if len(covered)>len(state_covered): best_station=station state_covered=covered final_station.add (best_station) states_needed-=state_covered print( final_station)