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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:51:42+00:00 2026-06-15T22:51:42+00:00

I am a n00b to Python and am attempting to bring the little bit

  • 0

I am a n00b to Python and am attempting to bring the little bit of knowledge I have from shell and PHP scripting to Python. I really trying to grasp the concepts of creating and manipulating the values within (while keeping the code in an understandable form).

I am having trouble utilizing the Python implementations of LISTS and MAPPINGS ( dict() ). I am writing a script that needs to use an associative array (a python mapping) inside of a basic array (a Python list). The list can use the typical INT index.

Thanks!

Here is what I have currently:

'''  Marrying old-school array concepts
[in Python verbiage] a list (arr1) of mappings (arr2)
[per my old-school training] a 2D array with 
        arr1 using an INT index
        arr2 using an associative index
'''
arr1 = []
arr1[0] = dict([    ('ticker'," "),
                        ('t_date'," "),
                        ('t_open'," "),
                        ('t_high'," "),
                        ('t_low'," "),
                        ('t_close'," "),
                        ('t_volume'," ")
                        ] )
arr1[1] = dict([    ('ticker'," "),
                        ('t_date'," "),
                        ('t_open'," "),
                        ('t_high'," "),
                        ('t_low'," "),
                        ('t_close'," "),
                        ('t_volume'," ")
                        ] )

arr1[0]['t_volume'] = 11250000
arr1[1]['t_volume'] = 11260000

print "\nAssociative array inside of an INT indexed array:"
print arr1[0]['t_volume'], arr1[1]['t_volume']

In PHP, I have the following example working:

'''
arr_desired[0] = array( 'ticker'        => 'ibm'
                            't_date'        => '1/1/2008'
                            't_open'        => 123.20
                            't_high'        => 123.20
                            't_low'     => 123.20
                            't_close'   => 123.20
                            't_volume'  => 11250000
                        );
arr_desired[1] = array( 'ticker'        => 'ibm'
                            't_date'        => '1/2/2008'
                            't_open'        => 124.20
                            't_high'        => 124.20
                            't_low'     => 124.20
                            't_close'   => 124.20
                            't_volume'  => 11260000
                        );

print arr_desired[0]['t_volume'],arr_desired[1]['t_volume'] # should print>>> 11250000 11260000
'''
  • 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-15T22:51:43+00:00Added an answer on June 15, 2026 at 10:51 pm

    Your list and dict literal definitions can be much simplified:

    keys = ['ticker', 't_date', 't_open', 't_high', 't_low', 't_close', 't_volume']
    arr1 = [
        dict.fromkeys(keys, ' '),
        dict.fromkeys(keys, ' ')
    ]
    

    I’m using the dict.fromkeys() method to initialize a dict with a sequence of keys, all with a given default value (a one-space string).

    When you define an empty list in Python, you cannot simply address elements that don’t exist. Alternatively, use the .append() method to add new elements to a list:

    arr1.append({'key': 'value', 'otherkey': 'othervalue'})
    

    The above example uses the {k: v} dict literal notation.

    I suspect you would benefit from reading the (excellent) Python tutorial first.

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

Sidebar

Related Questions

I have been doing a bit of programming in Python (still a n00b at
I'm a complete n00b to django & python. I come from a PHP background
I'm really a n00b when it comes to regular expressions. I've been trying to
If yes are there any frameworks/Tutorials/tips/etc recommended? N00b at Python but I have tons
this is probably a n00b question, but I don't really have any experience in
I'm a complete python n00b here and just trying to mash a few bits
n00b problem- I am trying to have a list show the most recent entry
note from N00B land again. I have read lots about sorting arrays - wanted
[Edit] changed return 0 to return . Side effects of beinga Python n00b. :)
Emacs n00b here, I've fiddled a bit with it in graphical mode and so

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.