Basic data structures
- Integrate notes from codebase.py
A tuple is a finite, ordered, immutable sequence of elements.
type((1)) # => int type(()) # => tuple type((1,)) # => tuple
Strings are a special type of array – one composed of characters.
Convert character string into unicode code point
(49, 50, 65, 66)
Convert unicode code point to character
('1', '2', 'A', 'B')
Trick to convert integer to string representation
Ignore minus sign in string number (using fact that
Slice from (and/or) to particular characters
this works because
Lookup has worst case time complexity O(n) and avearge time complexity O(1). Why?
Basic set difference a-b has time complexity O(len(a)) (for every element in a move to new set, if not in b) and space complexity O(len(a) + len(b)), since a new set is being created.
A variant is difference update, which has time complexity O(len(b)) (for every element in b remove from a if it exists) and space complexity O(1), as we don’t create a new set but update set a in place.
Stock(name='aapl', shares=200, price='55', date=None, time=None)
Use replace to populate named tuples with optional or missing fields
[Stock(name='IBM', shares=100, price=91.1, date=None, time=None), Stock(name='AAPL', shares=50, price=543.22, date=None, time=None), Stock(name='FB', shares=200, price=21.09, date=None, time=None)]