#!/usr/bin/env python # -*- coding: utf-8 -*- # 选择排序 # 时间复杂度O(n^2) def selection_sort(array): length = len(array) for m in range(length): k = 0 for i in range(1, length - m): if array[i] > array[k]: k = i array[length - 1 - m], array[k] = array[k], a
Python实现多属性排序 多属性排序:假如某对象有n个属性,那么先按某规则对属性a进行排序,在属性a相等的情况下再按某规则对属性b进行排序,以此类推. 现有对象Student: class Student: def __init__(self, name, math, history, chinese): self.name = name self.math = math self.history = history self.chinese = chinese 多属性排序: studentL
一:使用python对ip地址排序所用代码示例一: import socket iplist = ['10.5.11.1','192.168.1.33','10.5.2.4','10.5.1.3','10.5.11.13','10.5.11.12','10.5.1.1','10.5.1.2','10.5.1.11','10.5.1.13'] print(sorted(iplist,key=socket.inet_aton)) for i in sorted(iplist,key=socket.i
一些常用的排序 #系统内置排序算法#list.sort()#heapq模块 def sys_heap_sort(list): import heapq heap = [] for i in range(len(list)): heapq.heappush(heap,list[i]) for i in range(len(heap)): list[i] = heapq.heappop(heap) #python操作列表的方法,它们的时间复杂度 #insert() ---> O(n) #remov