[f(n) for f,n in zip((max,min,lambda s:float(sum(s))/len(s)),([list(map(int,map(input,':::')))]*3))]
# houses/serializers.py
class HousePlainSerializer(object):
"""
Serializes a House queryset consisting of dicts with
the following keys: 'id', 'address', 'country',
'sq_meters', 'price'.
"""
@staticmethod
def serialize_data(queryset):
"""
Return a list of hashed objects from the given queryset.
"""
return [
{
'id': Hasher.from_pk_and_class(entry['id'], House),
'address': entry['address'],
'country': Hasher.from_pk_and_class(entry['country'], Country),
'sq_meters': entry['sq_meters'],
'price': entry['price']
} for entry in queryset
]
# houses/views.py
class HouseListAPIView(ListAPIView):
model = House
serializer_class = HouseSerializer
plain_serializer_class = HousePlainSerializer # <-- added custom serializer
country = None
def get_queryset(self):
country = get_object_or_404(Country, pk=self.country)
queryset = self.model.objects.filter(country=country)
return queryset
def list(self, request, *args, **kwargs):
# Skipping validation code for brevity
country = self.request.GET.get("country")
self.country = Hasher.to_object_pk(country)
queryset = self.get_queryset()
data = self.plain_serializer_class.serialize_data(queryset) # <-- serialize
return Response(data)
https://www.kancloud.cn/luponu/airflow-doc-zh/889658
马走日 问题
class HorseRides:
def __init__(self, n, m, x, y):
self.row = n
self.column = m
self.startx = x
self.starty = y
self.chessboard = [[0]*self.column for r in range(self.row+1)]
self.sunx = [1, 1, 2, 2,-1,-1,-2,-2]
self.suny = [2,-2, 1,-1, 2,-2, 1,-1]
self.chessboard[self.startx][self.starty] = 1;
self.count = 0;
def check(self, x, y):
if x >= self.row or y >= self.column or x < 0 or y < 0 or self.chessboard[x][y] != 0:
return 0;
return 1;
def ride(self, x, y, step):
for i in range(8):
xx = x + self.sunx[i]
yy = y + self.suny[i]
if self.check(xx, yy) == 1:
self.chessboard[xx][yy] = step;
if step == self.row*self.column:
self.output();
else:
self.ride(xx, yy, step+1)
self.chessboard[xx][yy] = 0
def output(self):
self.count = self.count + 1
print "count = %d" % self.count
for i in range(self.row):
print self.chessboard[i]
def getCount(self):
return self.count
if __name__ == "__main__":
horseride = HorseRides(5,4,0,0)
horseride.ride(0, 0, 2)
print "total path: %d" % horseride.getCount()