Python: Retrieve Items From List

38798
2
11-01-2011 06:24 AM
LornaMurison
Occasional Contributor
Hi everyone,
I'm struggling with solving the problem described in this thread:
http://forums.arcgis.com/threads/39912-looped-block-selections

I started a new thread because I have questions specifically related to lists in python.
Lets say my list is:
list = [2,4,6,8]
I want to be able to do 2 things which I thought should be fairly simple:
1. Get the total number of items in the list (4)
2. Get the value of a list item at a specific index (eg. return 6 for index value 3 - or 2 if the index starts at 0)

The methods listed here: http://docs.python.org/tutorial/datastructures.html don't seem to do either of those things.  Is there some alternate method or object that would allow me to do that?
Thanks!
Tags (2)
0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
Length of list
len(listing)

Get index starts at zero, so for your example
listing = [2,4,6,8]

To get 6 you would do
listing[2]
0 Kudos
LornaMurison
Occasional Contributor
Perfect
Thank-you!!
0 Kudos