Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Python programming help?

so i have a list in python, of baseball players

and its under the variable baseballPlayers, so it looks like this:

baseballPlayers = ['Cabrera', 'Kinsler', 'Martinez', 'Hunter']

now if i type

print(baseballPlayers[1]) it will show up 'kinsler', which is correct, cause it starts off as 0, cabrera, 1, kinsler, 2, martinez, 3, hunter, but what i want to know is, how do i print off those numbers?

lets say i have an input() selection, and the user were to type in "kinsler" i want it to come back as [1], to show where it was in the list.

help!

1 Answer

Relevance
  • 7 years ago

    print (baseballPlayers.index('kinsler'))

    Something more complicated is required if there are duplicates in the list

Still have questions? Get your answers by asking now.