
Teaching practical programming through real-world applications. Tweets by @MikeHerman and @JanGiacomelli.
Denver, CO
Joined December 2017
- Tweets24.4K
- Following169
- Followers38.6K
- Likes8.6K
Python tip:
Concatenating strings with += in a loop is O(n^2) because each concatenation creates a new string.
Use join() for O(n) complexity.
馃憞
Python tip:
Time complexity for appending to a list in Python is O(1), but inserting is O(n).
"collections.deque" has time complexity of O(1) for appending on either end.
馃憞
Python tip:
Nested loops have multiplicative complexity.
A loop inside another loop typically results in O(n^2) time complexity, impacting performance with large datasets.
馃憞
10
1,049
Python tip:
Only immutable types can be used as dictionary keys in Python.
This is because a dictionary key must be hashable, and mutable types like lists or dictionaries aren't hashable.
Example 馃憞
May Santa leave under your tree a lot of readable code, AI agents that don't do anything stupid, tests that fail only when they should, deployments that behave the same in CI and prod, and just enough bugs to keep life interesting - but never on Fridays.
1
5
511
Python tip:
Using isinstance(obj, type) instead of type(obj) == type for type checking allows subclass compatibility, enhancing flexibility in code.
Example 馃憞
Python tip:
In Python, slicing a list creates a shallow copy.
This means changes to elements of the sliced list won't affect the original, but changes to mutable elements inside will.
Example 馃憞
3
583
Python tip:
In Python, two strings with the same content might have the same identity due to an optimization called string interning.
This isn't guaranteed for all strings, so it's important to use "==" for equality rather than "is" for identity.
7
522
Python tip:
A shallow copy (copy.copy()) duplicates the object but not its nested elements.
A deep copy (copy.deepcopy()) also duplicates all nested elements.
Changes in nested elements of a shallow copy affect the original, unlike in a deep copy.
Python tip:
In Python, None is a singleton object. There is only one instance of None throughout a Python program, making it unique compared to other objects.
Example 馃憞
Python tip:
In Python, using += on a list modifies the list in place. However, for tuples, which are immutable, += creates a new tuple.
Example 馃憞
Python tip:
The statement if '__name__ == "__main__"' in Python is used to check whether a Python script is being run directly or being imported as a module.
If the script is run directly, "__name__" is set to "__main__".













