Python string with space and without space at the end and immutability

This is a quirk of how the CPython implementation chooses to cache string literals. String literals with the same contents may refer to the same string object, but they don’t have to. ‘string’ happens to be automatically interned when ‘string ‘ isn’t because ‘string’ contains only characters allowed in a Python identifier. I have no … Read more

list() uses slightly more memory than list comprehension

I think you’re seeing over-allocation patterns this is a sample from the source: /* This over-allocates proportional to the list size, making room * for additional growth. The over-allocation is mild, but is * enough to give linear-time amortized behavior over a long * sequence of appends() in the presence of a poorly-performing * system … Read more