Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
All Array Index
#1
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)
Reply
#2
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.
JohnnyCoffee likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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?
Reply
#4
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.
JohnnyCoffee likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  change array elements dependent on index SchroedingersLion 1 2,171 Nov-22-2019, 06:25 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020