Python - Count elements in list

Bruce picture Bruce · Nov 9, 2010 · Viewed 1M times · Source

I am trying to find a simple way of getting a count of the number of elements in a list:

MyList = ["a", "b", "c"]

I want to know there are 3 elements in this list.

Answer

Ignacio Vazquez-Abrams picture Ignacio Vazquez-Abrams · Nov 9, 2010

len()

>>> someList=[]
>>> print len(someList)
0