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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:39:13+00:00 2026-05-17T00:39:13+00:00

Is it possible to use strings as indices in an array in python? For

  • 0

Is it possible to use strings as indices in an array in python?

For example:

myArray = []
myArray["john"] = "johns value"
myArray["jeff"] = "jeffs value"
print myArray["john"]
  • 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-17T00:39:14+00:00Added an answer on May 17, 2026 at 12:39 am

    What you want is called an associative array. In python these are called dictionaries.

    Dictionaries are sometimes found in other languages as “associative memories” or “associative arrays”. Unlike sequences, which are indexed by a range of numbers, dictionaries are indexed by keys, which can be any immutable type; strings and numbers can always be keys.

    myDict = {}
    myDict["john"] = "johns value"
    myDict["jeff"] = "jeffs value"
    

    Alternative way to create the above dict:

    myDict = {"john": "johns value", "jeff": "jeffs value"}
    

    Accessing values:

    print(myDict["jeff"]) # => "jeffs value"
    

    Getting the keys (in Python v2):

    print(myDict.keys()) # => ["john", "jeff"]
    

    In Python 3, you’ll get a dict_keys, which is a view and a bit more efficient (see views docs and PEP 3106 for details).

    print(myDict.keys()) # => dict_keys(['john', 'jeff']) 
    

    If you want to learn about python dictionary internals, I recommend this ~25 min video presentation: https://www.youtube.com/watch?v=C4Kc8xzcA68. It’s called the “The Mighty Dictionary”.

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

Sidebar

Related Questions

Possible Duplicate: Why use iterators instead of array indices? string::iterator it; for (it =
Is it possible to use numpy.memmap to map a large disk-based array of strings
Is it possible to use Windows API ANSI functions with UTF-8 strings? For example,
Is it possible to use routing and query strings together? An example would be
Possible Duplicate: Enforcing spaces in string resources This is the strings.xml file I use
Is it possible to use the NSLocalizedString infrastructure (based on localizable.strings) with a custom-defined
Why is it not possible to use enum values as strings in a switch
An application I use exports strings of data in an array in one cell,
I'm wondering if its possible to use string substitution along with the python re
is it possible to use ressources like strings that are defined in library projects

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.