Python Forum
All Array Index - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: All Array Index (/thread-32687.html)



All Array Index - JohnnyCoffee - Feb-26-2021

In the example below, how do I list all (index numbers) of the existing elements of the array because using the index () without passing one or more arguments generates an error: TypeError: index expected at least 1 argument, got 0. Remembering that I need to list all indexes !

letter = ['a', 'e', 'i', 'o', 'i', 'u']
output = letter.index()
print(output)



RE: All Array Index - buran - Feb-26-2021

spam = ['a', 'e', 'i', 'o', 'i', 'u']
for idx, char in enumerate(spam):
    print(f'{idx} --> {char}')
Output:
0 --> a 1 --> e 2 --> i 3 --> o 4 --> i 5 --> u
Now the question is do you really need the indexes.


RE: All Array Index - JohnnyCoffee - Feb-26-2021

(Feb-26-2021, 05:53 AM)buran Wrote:
spam = ['a', 'e', 'i', 'o', 'i', 'u']
for idx, char in enumerate(spam):
    print(f'{idx} --> {char}')
Output:
0 --> a 1 --> e 2 --> i 3 --> o 4 --> i 5 --> u
Now the question is do you really need the indexes.

Yes, I thank buran and within the context how do I access a certain value from within the array by idx?


RE: All Array Index - ndc85430 - Feb-26-2021

This is a really basic thing and it's surprising you're having to ask. It's easily found in any introductory materials on the language, e.g the Python tutorial.