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".

Answer from miku on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_string_index.asp
Python String index() Method
Remove List Duplicates Reverse ... Python Interview Q&A Python Bootcamp Python Training ... The index() method finds the first occurrence of the specified value....
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-find-index-containing-string-in-list
Python - Find Index containing String in List - GeeksforGeeks
July 23, 2025 - It involves identifying the position where a specific string appears within the list. index() method in Python is used to find the position of a specific string in a list.
Discussions

Python Array with String Indices - Stack Overflow
Is it possible to use strings as indices in an array in python? ... Save this answer. ... Show activity on this post. 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 ... More on stackoverflow.com
🌐 stackoverflow.com
How can I get the index of a string in Python list, which contains a certain character? - Stack Overflow
I have put multiple strings in a list with the line.split(":") method and one of them contains a certain character I want to find and return its index in the list. For example: s = "... More on stackoverflow.com
🌐 stackoverflow.com
How do I search a list of Strings for a certain word and return the index?
How do I search the list for "Berlin" and get the index of the sentence containing "Berlin"? Loop over each element in cities with the enumerate function and check if Berlin is in each. enumerate returns a tuple with the index and the value at that index. cities = ["The capital of france is Paris", "The capital of france is Berlin"," The capital of france is London"," The capital of france is Barcelona"] query = 'Berlin' for index, value in enumerate(cities): if query in value: print(f"The sentence containing '{query}' is at index '{index}'!") >>> The sentence containing 'Berlin' is at index '1'! More on reddit.com
🌐 r/learnpython
5
1
January 25, 2021
Trying to format a list of floats with f-strings
You can't format an entire list all at once. You have to format each number individually, and then unpack that to print it: print("Roots:", *(f"{x:.3f}" for x in roots)) or you could use join to combine the formatted numbers: print("Roots:", ' '.join(f"{x:.3f}" for x in roots)) More on reddit.com
🌐 r/learnpython
6
2
July 23, 2018
🌐
Programiz
programiz.com › python-programming › methods › list › index
Python List index()
Note: The index() method only returns the first occurrence of the matching element. # vowels list vowels = ['a', 'e', 'i', 'o', 'i', 'u'] # index of 'e' in vowels
🌐
Programiz
programiz.com › python-programming › methods › string › index
Python String index()
The index() method returns the index of a substring inside the string (if found).
🌐
FavTutor
favtutor.com › blogs › get-list-index-python
Python Find String Position in List (Get the Index of an Item)
1 week ago - Learn how to find the position of a string in a list in Python using index(), enumerate, and in, with examples for all positions and safe searching.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-index-and-slice-strings-in-python-3
How To Index and Slice Strings in Python | DigitalOcean
September 29, 2025 - You should have Python 3 installed and a programming environment set up on your computer or server. If you don’t have a programming environment set up, you can refer to the installation and setup guides for a local programming environment or for a programming environment on your server appropriate for your operating system (Ubuntu, CentOS, Debian, etc.) Like the list data type that has items that correspond to an index number, each of a string’s characters also correspond to an index number, starting with the index number 0.
Find elsewhere
🌐
datagy
datagy.io › home › python posts › python strings › python: find an index (or all) of a substring in a string
Python: Find an Index (or all) of a Substring in a String • datagy
December 20, 2022 - Check out my in-depth tutorial about Python list comprehensions here, which will teach you all you need to know! Let’s see how we can accomplish this using a list comprehension: a_string = "the quick brown fox jumps over the lazy dog. the quick brown fox jumps over the lazy dog" # Find all indices of 'the' indices = [index for index in range(len(a_string)) if a_string.startswith('the', index)] print(indices) # Returns: [0, 31, 45, 76]
🌐
TutorialsPoint
tutorialspoint.com › article › python-character-indices-mapping-in-string-list
Python – Character indices Mapping in String List
When working with string lists, you may need to map each character to the indices where it appears. Python provides an efficient solution using defaultdict from the collections module combined with enumeration and set operations. from collections import defaultdict result = defaultdict(set) for index, string in enumerate(string_list): for char in string.split(): result[char].add(index + 1)
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-string-index-method
Python String index() Method - GeeksforGeeks
May 2, 2025 - Explanation: index() method searches for the substring "prog" within "Python programming" and returns starting index 7. ... end (optional): The ending index for the search. If not provided, it defaults to the length of the string.
🌐
TutorialsPoint
tutorialspoint.com › article › python-find-index-containing-string-in-list
Python - Find Index Containing String in List
March 27, 2026 - When searching for all indices of a particular string value, use this approach ? def find_all_indices(target, search_list): indices = [] start = 0 while True: try: index = search_list.index(target, start) indices.append(index) start = index + 1 except ValueError: break return indices test_list = ["Python", "Java", "Python", "C++", "Python"] result = find_all_indices("Python", test_list) print(f"All indices of 'Python': {result}")
🌐
Simplilearn
simplilearn.com › home › resources › software development › python index: mastering list indexing techniques
Python List index() Method Explained with Examples
3 weeks ago - The Python index() method helps you find the index position of an element or an item in a string of characters or a list of items.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Built In
builtin.com › software-engineering-perspectives › python-substring-indexof
5 Ways to Find the Index of a Substring in Python | Built In
The index() method in Python finds the first occurrence of a specific character or element in a string or list. If the character or element is found, its index value will be returned.
🌐
Railsware
railsware.com › home › engineering › indexing and slicing for lists, tuples, strings, other sequential types in python
Python Indexing and Slicing for Lists, Tuples, Strings, other Sequential Types | Railsware Blog
January 22, 2025 - Python supports slice notation for any sequential data type like lists, strings, tuples, bytes, bytearrays, and ranges. Also, any new data structure can add its support as well. This is greatly used (and abused) in NumPy and Pandas libraries, which are so popular in Machine Learning and Data Science. It’s a good example of “learn once, use everywhere”. In this article, we will focus on indexing and slicing operations over Python’s lists.
🌐
Codecademy
codecademy.com › learn › dacp-python-fundamentals › modules › dscp-python-strings › cheatsheet
Python Fundamentals: Python Strings Cheatsheet | Codecademy
In Python, the built-in len() function can be used to determine the length of an object. It can be used to compute the length of strings, lists, sets, and other countable objects. ... The Python string method .find() returns the index of the first occurrence of the string passed as the argument...
🌐
University of Pittsburgh
sites.pitt.edu › ~naraehan › python3 › mbb7.html
Python 3 Notes: Introduction to Lists, Indexing
Python 3 Notes [ HOME | LING 1330/2330 ] Tutorial 7: Introduction to Lists, Indexing << Previous Tutorial Next Tutorial >> On this page: list, list indexing with [], len(), string indexing with []. Video Tutorial Python 3 Changes NONE! Python 2 vs. 3 Summary · Video Summary Lists are created ...
🌐
freeCodeCamp
freecodecamp.org › news › python-find-in-list-how-to-find-the-index-of-an-item-or-element-in-a-list
Python Find in List – How to Find the Index of an Item or Element in a List
February 24, 2022 - Here is how you would get all indices of each occurrence of the string "Python", using list comprehension: programming_languages = ["JavaScript","Python","Java","Python","C++","Python"] python_indices = [index for (index, item) in enumerate(programming_languages) if item == "Python"] print(python_indices) #[1, 3, 5]
🌐
Tutorialspoint
tutorialspoint.com › python › string_index.htm
Python String index() Method
The following is an example of the python string find() method. In this we have created a string "Hello! Welcome to Tutorialspoint" and, trying to find the word "to" in it. str1 = "Hello! Welcome to Tutorialspoint." str2 = "to"; result= str1.index(str2) print("The index where the substring is found:", result)