5

Is there any good reference resource to know the time complexity of Python's built-in functions like dict.fromkeys(), .lower()? I found links like this UCI resource which lists time-complexity for basic list & set operations but of course, not for all built-ins. I also found Python Reference - The Right Way but most of references have #TODO for time complexity.

I also tried reading the source code of python built-ins to figure out how the functions like dict.fromkeys() are implemented but felt lost.

3
  • 2
    One resource: wiki.python.org/moin/TimeComplexity Commented Jan 21, 2019 at 0:41
  • @AChampion: Thanks for providing the link but it also doesn't provide info on time complexity for string data types, and also misses operations (like dict.fromkeys()) while listing operations on dict. Commented Jan 21, 2019 at 1:19
  • did you find out time complexity of .lower() @Vimanyu Commented Jul 1, 2023 at 11:52

1 Answer 1

3

This is a great place to start:

https://wiki.python.org/moin/TimeComplexity

It says that Get Item is O(1) and Iteration is O(n) (Average Case). So then, if with .fromkeys() you iterate over just the keys of the dict, then make those the keys of a new dict, while also setting values, I'd think that you'd have between O(n) and O(2n), where n is the number of keys in the first dict.

Sorry that I can't offer more than conjecture, but hopefully that link is helpful.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.