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 4536378
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:31:45+00:00 2026-05-21T14:31:45+00:00

I want to say a[current] = value rather than saying a.append(value) because I want

  • 0

I want to say

a[current] = value 

rather than saying

a.append(value)

because I want to show that the current value is value. The former listing shows this better. I come from C, so I am a bit confused with python lists. In C I preallocate space, so a[current] would exist and contain junk before I assign it value. Can I do something similar in Python?

  • 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-05-21T14:31:45+00:00Added an answer on May 21, 2026 at 2:31 pm

    When I first started using Python I ran into this problem all the time. You can do things like ‘[0]*10’, but is inelegant, and will cause you problems if you try to do the same thing for lists of lists.

    I finally solved the problem by realizing most of the time I just needed to reformulate the problem into something more pythonic. List comprehensions (as noted above) will almost always be the correct answer. If you are preallocating space, that means you are probably going to iterate over some other list, do some operation, then set an element in the new list to that value:

     newList = [op(e) for e in oldList]
    

    You can get fancier. If for example, you don’t want all the elements, you can set up a filter:

     newList = [op(e) for e in oldList if e < 5]
    

    which will only put items that are less than 5 into the newList.

    However, sometimes list comprehension isn’t want you want. For example, if you’re doing math-oriented coding, then numpy can come to the rescue:

      myVector = numpy.zeros(10)
    

    will create an array with 10 elements.

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

Sidebar

Related Questions

I want to use the current cell value in a formula. Let's say i
At first I want to say: I couldn't find a support forum for this
First thing i want to say that it's not an easy question to explain,
First off I want to say that I am not using threads or multiple
First of all i want to say that i have searched each and every
First of all i want to say that I'm still a beginner in ASP.NET
First, I just want to say that the stackoverflow community is empowering to say
This is probably a simple where clause but I want to say, from columnX
Hi Masters Of Web Development, first I want to say that I did not
I have a table that looks like this, Date Value 01/01/2010 03:59:00 324.44 01/02/2010

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.