I have read alot of strange syntaxerror questions and have not seen mine among it yet and I am really at a loss. I am doing some homework for which the deadline is coming closer and this error I cant get rid of:
def create_voting_dict():
strlist = [voting_data[i].split() for i in range(len(voting_data))]
return voting_dict = {strlist[h][0]:[int(strlist[h][g]) for g in range(3, len(strlist[h]))] for h in range(len(strlist))}
Which gets me the error:
return voting_dict = {strlist[h][0]:[int(strlist[h][g]) for g in range(3, len(strlist[h]))] for h in range(len(strlist))}
^
SyntaxError: invalid syntax
This error did not occur when I defined voting_dict inside the procedure, but I need to define it globally so i put it after return and then I got the error. Have been counting parenthesis all over but that doesnt seem to be the problem.
I am sure that when I see the problem it is very easy, but I just dont see it. Thanks for any help.
*voting data is a list with strings and I made the procedure to split the strings and create a dictionary
range(len(…))calls? Why not just{outer[0]: [int(inner) for inner in outer[3:]] for outer in strlist]}?