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

  • Home
  • SEARCH
  • 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

The general rule is that I want to say, T has a method with
Lets say you want to create a listing of widgets The Widget Manufacturers all
Let's say I want a web page that contains a Flash applet and I'd
Without thinking about it at all I just want to say I should allow
Let's say I want to run a .NET application on a machine where the
Say you want a simple maze on an N by M grid, with one
Let's say I want a way to display just the the center 50x50px of
Say you want to generate a matched list of identifiers and strings enum {
I want to insert say 50,000 records into sql server database 2000 at a
Let's say I want to write a regular expression to change all <abc> ,

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.