Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- Stock = collections.namedtuple('Stock', 'symbol, open, high, low, close, volume')
- stocks = [
- Stock('AAL', 49, 49.1, 48.47, 48.63, 11901883),
- Stock('AAPL', 145.13, 147.16, 145.11, 146.28, 33917635),
- Stock('ADBE', 143.75, 145.59, 143.06, 145.41, 3383524),
- Stock('AMZN', 1002.54, 1004.62, 998.02, 1003.74, 2832807),
- Stock('GOOGL', 975.5, 986.62, 974.46, 986.09, 1524905),
- Stock('MAT', 20.22, 20.75, 20.11, 20.68, 10603967),
- Stock('MSFT', 70.09, 71.25, 69.92, 71.21, 26803888),
- Stock('NTES', 320, 333.78, 319, 333.56, 1356386),
- ]
- print(stocks)
- # Remember lambda expressions look like this
- # lambda value: value.property
- print("Stock with highest high: ")
- ans = sorted(stocks)[0]
- print(ans.high, ans.symbol)
- print("Stock with lowest low: ")
- ans = sorted(stocks)[0]
- print(ans.symbol, ans.low)
- print("highest volume: ")
- ans = sorted(stocks)[0]
- print(ans.symbol, "{:,}".format(ans.volume))
- print("Stock with lowest volume: ")
- ans = sorted(stocks)[0]
- print(ans.symbol, "{:,}".format(ans.volume))
- stocks.sort()
- print(stocks)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement