Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import collections
  2.  
  3. Stock = collections.namedtuple('Stock', 'symbol, open, high, low, close, volume')
  4.  
  5. stocks = [
  6. Stock('AAL', 49, 49.1, 48.47, 48.63, 11901883),
  7. Stock('AAPL', 145.13, 147.16, 145.11, 146.28, 33917635),
  8. Stock('ADBE', 143.75, 145.59, 143.06, 145.41, 3383524),
  9. Stock('AMZN', 1002.54, 1004.62, 998.02, 1003.74, 2832807),
  10. Stock('GOOGL', 975.5, 986.62, 974.46, 986.09, 1524905),
  11. Stock('MAT', 20.22, 20.75, 20.11, 20.68, 10603967),
  12. Stock('MSFT', 70.09, 71.25, 69.92, 71.21, 26803888),
  13. Stock('NTES', 320, 333.78, 319, 333.56, 1356386),
  14. ]
  15.  
  16. print(stocks)
  17.  
  18. # Remember lambda expressions look like this
  19. # lambda value: value.property
  20.  
  21. print("Stock with highest high: ")
  22. ans = sorted(stocks)[0]
  23. print(ans.high, ans.symbol)
  24.  
  25. print("Stock with lowest low: ")
  26. ans = sorted(stocks)[0]
  27. print(ans.symbol, ans.low)
  28.  
  29. print("highest volume: ")
  30. ans = sorted(stocks)[0]
  31. print(ans.symbol, "{:,}".format(ans.volume))
  32.  
  33. print("Stock with lowest volume: ")
  34. ans = sorted(stocks)[0]
  35. print(ans.symbol, "{:,}".format(ans.volume))
  36.  
  37. stocks.sort()
  38. print(stocks)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement