Python list comprehension syntax error
list-comprehension, python
Solution
A list comprehension won't work here, since you're not at any time building a list - you are changing values in various dictionaries. A list comprehension would be the right tool if your original code was of the form:
currentservertime = []
for item in results:
currentservertime.append(int(time.time())
Which would translate into the list comprehension:
currentservertime = [int(time.time()) for item in results]
As it stands, your existing loop is the clearest and most direct way to implement what you're doing.
Problem
Using a for loop, the following python code works. ``` for item in results: item ['currentservertime'] = int(time.time()) ``` I would like to do it with a list comprehension however. So I have tried the following, but i get a syntax error on the = ``` item['currentservertime'] = int(time.time()) for item in results ``` where am i going wrong?