Linked Questions

32 questions linked to/from Cost of len() function
9 votes
2 answers
7k views

Possible Duplicate: Cost of len() function Does len() iterate over the objects in a list and then return their count? Thus giving it a O(n). Or.... Does a python list keep a count of any objects ...
mjgpy3's user avatar
  • 8,993
13 votes
1 answer
4k views

Python has many built-in functions, and len() is one of them. Return the length (the number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or ...
NPN328's user avatar
  • 1,962
7 votes
4 answers
669 views

Possible Duplicate: Cost of len() function How Python calculates length of a list(using len() function )?Does it go through a for or while loop to do the same or it has some internal variable that ...
user1037114's user avatar
4 votes
1 answer
5k views

Until now, when I used the len function with various container types (let's say the list type for now), I assumed that each container type has a field member which stores the length of that particular ...
rboy's user avatar
  • 788
0 votes
0 answers
46 views

Whats the most pythonic or efficent way to check if two lists are equal in size? The only thing I can think of is len(list_a) == len(list_b) but that seems like it would take a lot more processing ...
3222 votes
27 answers
5.4m views

For example, if passed the following: a = [] How do I check to see if a is empty?
Ray's user avatar
  • 194k
324 votes
6 answers
693k views

I have a a dictionary mapping keywords to the repetition of the keyword, but I only want a list of distinct words so I wanted to count the number of keywords. Is there a way to count the number of ...
Dan's user avatar
  • 8,553
269 votes
5 answers
326k views

When writing test cases, I often need to assert that two list contain the same elements without regard to their order. I have been doing this by converting the lists to sets. Is there any simpler ...
satoru's user avatar
  • 33.4k
72 votes
7 answers
520k views

I have created a 2 dimension array like: rows =3 columns= 2 mylist = [[0 for x in range(columns)] for x in range(rows)] for i in range(rows): for j in range(columns): mylist[i][j] = '%s,%...
17 votes
3 answers
19k views

I see a lot of questions about the run-time complexity of python's built in methods, and there are a lot of answers for a lot of the methods (e.g. https://wiki.python.org/moin/TimeComplexity , https://...
23 votes
3 answers
5k views

In Python, len is a function to get the length of a collection by calling an object's __len__ method: def len(x): return x.__len__() So I would expect direct call of __len__() to be at least as ...
Ωmega's user avatar
  • 44k
9 votes
6 answers
1k views

I am looking for a very rapid way to check whether a folder contains more than 2 files. I worry that len(os.listdir('/path/')) > 2 may become very slow if there are a lot of files in /path/, ...
bluppfisk's user avatar
  • 2,732
11 votes
2 answers
5k views

Example: a = {a:'1', b:'2'} len(a) What is the time complexity of len(a) ?
8 votes
10 answers
318 views

I have two sorted lists, e.g. a = [1, 4, 7, 8] b = [1, 2, 3, 4, 5, 6] I want to know for each item in a if it is in b. For the above example, I want to find a_in_b = [True, True, False, False] (or ...
Tom de Geus's user avatar
  • 6,053
11 votes
4 answers
3k views

A similar question has already been ask Cost of len() function here. However, this question looks at the cost of len it self. Suppose, I have a code that repeats many times len(List), every time is O(...
oz123's user avatar
  • 29.1k

15 30 50 per page
1
2 3