摘要:
使用strip()默认将 str 两端的空白字符去除掉 同时还有rstrip() 和 lstrip() 方法, 作用分别为去除 右边的空白字符/左边的空白字符 阅读全文
摘要:
通过set()方法可以实现列表的去重, 但是需要使用list()将结果重新转化为列表 阅读全文
摘要:
student = [{"no": 1,"score": 90},{"no": 2,"score": 90},{"no": 3,"score": 88},{"no": 4,"score": 92}] # 单级排序,仅按照score排序 student_sort_1 = sorted(student, key=lambda e: e.__getitem__('score')) # 多级排序,先... 阅读全文
摘要:
一.使用reversed()函数 注意:reversed()函数返回的是一个迭代器,而不是一个List,需要再使用List函数转换一下。 二.使用切片 三.使用sorted() 其中reverse=True是按降序排列,reverse=False是按照升序排列 阅读全文
摘要:
在web开发中很多需求都需要实现分页功能,然而 Django Rest Framework 自带的分页功能,只能在 mixins.ListModelMixin and generics.GenericAPIView classes 继承这两个类才可以使用,而我们通常为了灵活性,往往会继承APIVie 阅读全文