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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:19:30+00:00 2026-05-11T02:19:30+00:00

This is an incredibly simple question (I’m new to Python). I basically want a

  • 0

This is an incredibly simple question (I’m new to Python).

I basically want a data structure like a PHP array — i.e., I want to initialise it and then just add values into it.

As far as I can tell, this is not possible with Python, so I’ve got the maximum value I might want to use as an index, but I can’t figure out how to create an empty list of a specified length.

Also, is a list the right data structure to use to model what feels like it should just be an array? I tried to use an array, but it seemed unhappy with storing strings.

Edit: Sorry, I didn’t explain very clearly what I was looking for. When I add items into the list, I do not want to put them in in sequence, but rather I want to insert them into specified slots in the list.

I.e., I want to be able to do this:

list = []  for row in rows:   c = list_of_categories.index(row['id'])   print c   list[c] = row['name'] 
  • 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. 2026-05-11T02:19:30+00:00Added an answer on May 11, 2026 at 2:19 am

    Depending on how you are going to use the list, it may be that you actually want a dictionary. This will work:

    d = {}  for row in rows:   c = list_of_categories.index(row['id'])   print c   d[c] = row['name'] 

    … or more compactly:

    d = dict((list_of_categories.index(row['id']), row['name']) for row in rows) print d 

    PHP arrays are much more like Python dicts than they are like Python lists. For example, they can have strings for keys.

    And confusingly, Python has an array module, which is described as ‘efficient arrays of numeric values’, which is definitely not what you want.

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

Sidebar

Ask A Question

Stats

  • Questions 116k
  • Answers 116k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer [I was going to post this as a comment on… May 11, 2026 at 10:38 pm
  • Editorial Team
    Editorial Team added an answer Ok, just figured it out. Whilst regedit shows it as… May 11, 2026 at 10:38 pm
  • Editorial Team
    Editorial Team added an answer If you are able to, check from the server before… May 11, 2026 at 10:38 pm

Related Questions

This is an incredibly simple question (I'm new to Python). I basically want a
I have boiled down an issue I'm seeing in one of my applications to
I have a data object (let's say it's called 'Entry') that has a set
I have some nested tables that I want to hide/show upon a click on
I do most of my work with Microsoft technologies these days, so naturally I'm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.