for s in stocks_list:
print s
how do I know what "position" s is in? So that I can do stocks_list[4] in the future?
To find a position of the particular element you can use the index() method of List class with the element passed as an argument. An index() function returns an integer (position) of the first match of the specified element in the List.
Python – Find Index or Position of Element in a List. To find index of the first occurrence of an element in a given Python List, you can use index() method of List class with the element passed as argument. The index() method returns an integer that represents the index of first match of specified element in the List.
The index() method returns the index of the given element in the list. If the element is not found, a ValueError exception is raised.
To find the position of an element in an array, you use the indexOf() method. This method returns the index of the first occurrence the element that you want to find, or -1 if the element is not found. The following illustrates the syntax of the indexOf() method.
Python find the position/index of an element in List. To find a position of the particular element you can use the index () method of List class with the element passed as an argument. An index () function returns an integer (position) of the first match of the specified element in the List.
To find index of the first occurrence of an element in a given Python List, you can use index () method of List class with the element passed as argument. The index () method returns an integer that represents the index of first match of specified element in the List.
This is how getIndexes () founds the exact index positions of the given element & stores each position in the form of (row, column) tuple. Finally, it returns a list of tuples representing its index positions in the dataframe.
You can also provide start and end positions of the List, where the search has to happen in the list. Following is the syntax of index () function with start and end positions. start parameter is optional. If you provide a value for start, then end is optional. We shall look into examples, where we go through each of these scenarios in detail.
If you know what you're looking for ahead of time you can use the index method:
>>> stocks_list = ['AAPL', 'MSFT', 'GOOG']
>>> stocks_list.index('MSFT')
1
>>> stocks_list.index('GOOG')
2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With