About 429,000 results
Open links in new tab
  1. How do I get the number of elements in a list (length of a list) in …

    Nov 11, 2009 · Explanation Everything in Python is an object, including lists. All objects have a header of some sort in the C implementation. Lists and other similar builtin objects with a …

  2. In python, what does len(list) do? - Stack Overflow

    Apr 27, 2016 · Does len (list) calculate the length of the list every time it is called, or does it return the value of the built-in counter?I have a context where I need to check the length of a list …

  3. python - How to find length of an element in a list? - Stack Overflow

    Oct 23, 2015 · list_of_lengths = (lambda x:[len(i) for i in x])(lst) Longer explanation (from the inner brackets, moving outwards) We loop through our list and get the corresponding length value of …

  4. python - range (len (list)) or enumerate (list)? - Stack Overflow

    Aug 16, 2012 · 2 Assuming you're using Python 2.x, if you use len(), you should use xrange() as it will avoid creating a list of the numbers in the range. And in this case, I'd go with len() because …

  5. if len(list) in Python - Stack Overflow

    In Python, values that are considered 'empty', such as numeric 0, are considered False in a boolean context, and otherwise are True. Thus, len(f) is True if f has length, otherwise it is …

  6. How to get length of a list of lists in python - Stack Overflow

    The variable numLines prints out as '4' not '3'. So, len (myLines) is returning the number of elements in each list not the length of the list of lists." It sounds like you're reading in a .csv …

  7. What is the difference between len () and count () in python?

    Oct 25, 2014 · @msw: Python docs are excellent but also are too information dense when you are new to programming; and the list method docs are somewhat hidden. Lukas Graf had to link to …

  8. Python: for loops - for i in range(0,len(list) vs for i in list

    Oct 4, 2015 · 9 This is a really simple python mechanics question. Why can't I just say for i in range original_list instead of for i in range (0, len (original_list)). Do people usually use range …

  9. python - indexing list with len (list) vs len (list) - 1 - Stack Overflow

    May 22, 2013 · To get a slice with the first element only, you'll need list[0:1] instead. (I'm using a list with just 1 element because it's super simple to understand. It obviously holds for lists with …

  10. python - Difference between len () and .__len__ ()? - Stack Overflow

    Well, len(s) is a built-in Python method which returns the length of an object. Now __len__() is a special method that is internally called by len(s) method to return the length of an object.