Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8430447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:35:43+00:00 2026-06-10T05:35:43+00:00

Using a for loop, the following python code works. for item in results: item

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:35:44+00:00Added an answer on June 10, 2026 at 5:35 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Within a for loop, I'm using the following code to convert from one date
So I create multiple BackgroundWorkers using loop: foreach (var item in list) { worker
I just designed a simple For Loop using window form application. I would like
How do I write the following loop using Python's implicit looping? def kl(myA, myB,
Edit: Just for clarification I am using python, and would like to do this
I would like some advice. I have encountered the following error in Python 2.6:
I have opened a shelve using the following code: #!/usr/bin/python import shelve #Module:Shelve is
I am trying to loop through a tab-delimited file of election results using Python.
I am using the following loop to send/attach multiple attachments to my email message.
I am using the following loop to add items to an an array. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.