Python:SyntaxError:" for"上的语法无效

时间:2016-12-06 01:09:14

标签: python syntax

当我尝试在Python中编译代码时,我收到此错误消息。好像它不喜欢我的" for"。

File "flow.py", line 74

strat_improvements = {strategy: 0 for strategy in STRATEGIES}

                                    ^

SyntaxError: invalid syntax

有人可以告诉我为什么会这样吗?我对Python比较陌生。这是一个代码块......

def solve(data):
    """Solves an instance of the flow shop scheduling problem"""

    # We initialize the strategies here to avoid cyclic import issues                                                                                                                               
    initialize_strategies()
    global STRATEGIES

    # Record the following for each strategy:                                                                                                                                                       
    #  improvements: The amount a solution was improved by this strategy                                                                                                                            
    #  time_spent: The amount of time spent on the strategy                                                                                                                                         
    #  weights: The weights that correspond to how good a strategy is                                                                                                                               
    #  usage: The number of times we use a strategy                                                                                                                                                 
    strat_improvements = {strategy:
                          0 for strategy in STRATEGIES}
    strat_time_spent = {strategy: 0 for strategy in STRATEGIES}
    strat_weights = {strategy: 1 for strategy in STRATEGIES}
    strat_usage = {strategy: 0 for strategy in STRATEGIES}

    # Start with a random permutation of the jobs                                                                                                                                                   
    perm = range(len(data))
    random.shuffle(perm)

    # Keep track of the best solution                                                                                                                                                               
    best_make = makespan(data, perm)
    best_perm = perm
    res = best_make

0 个答案:

没有答案