MCPcopy Create free account
hub / github.com/dabeaz-course/python-mastery / RideData

Class RideData

Solutions/2_5/readrides.py:91–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89
90import collections
91class RideData(collections.Sequence):
92 def __init__(self):
93 # Each value is a list with all of the values (a column)
94 self.routes = []
95 self.dates = []
96 self.daytypes = []
97 self.numrides = []
98
99 def __len__(self):
100 # All lists assumed to have the same length
101 return len(self.routes)
102
103 def append(self, d):
104 self.routes.append(d['route'])
105 self.dates.append(d['date'])
106 self.daytypes.append(d['daytype'])
107 self.numrides.append(d['rides'])
108
109 def __getitem__(self, index):
110 return { 'route': self.routes[index],
111 'date': self.dates[index],
112 'daytype': self.daytypes[index],
113 'rides': self.numrides[index] }
114
115# Modified version using RideData
116def read_rides_as_dicts(filename):

Callers 1

read_rides_as_dictsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected