Which performance have cPython sets in comparison to lists?

AFAIK, the Python "specification" does not impose specific data structures for implementation of lists, dictionaries or sets, so this can't be answered "officially". If you're only concerned about CPython (the reference implementation), then we can throw in some un-official complexities. You might want to re-formulate your question to target a specific Python implementation.

AFAIK, the Python "specification" does not impose specific data structures for implementation of lists, dictionaries or sets, so this can't be answered "officially". If you're only concerned about CPython (the reference implementation), then we can throw in some un-official complexities. You might want to re-formulate your question to target a specific Python implementation.In any case, the complexities you mentioned can't be right.

Supposing a dynamically-resized array implementation, appending an item is amortized O(1): most often you simple copy the new value, and in the worst case, you need to re-allocate, copying all n items, plus the new one. Next, inserting has exactly the same worst case scenario, so it has the same upper bound on complexity, but in the best case, it only moves k items, where k is the number of items past the position where you're inserting.

In general it's safe to assume CPython. Code must be able to rely on the complexity of operations on core types--that's a fundamental necessity for using them. Specified or not, all implementations must match the reference implementation if they expect compatibility.(There are a couple gotchas; off-hand, s += x for strings comes to mind.) – Glenn Maynard Mar 6 at 23:44 1 No, you must match the reference implementation if you expect to be able to run production Python code.

If you don't, then software will break. – Glenn Maynard Mar 6 at 23:56 2 @Kanchi: In the real world, a one-second algorithm taking ten minutes due to a fundamental O(1) operation being O(n) is broken. – Glenn Maynard Mar 7 at 0:30 1 Ah, but you preclude the possibility that the non-reference implementation might actually be better than the reference implementation.

While this is fairly unlikely for fundamental things, Java's implementation of foo (and thus Jython's) might be better than CPython's. – Chinmay Kanchi Mar 7 at 0:41 1 @Glenn: it doesn't matter. You can't assume that something which differs from the reference implementation, yet not specified is "non-compliant" and must be fixed, or there would be no point in leaving wiggle room in the spec, or even writing a spec in the first place.

You should avoid writing code that depends on some specific internals to CPython, because it makes your code non-portable to other implementations. The classic example is people relying on a reference-counted garbage collector. – André Caron Mar 7 at 15:05.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions