#!/usr/bin/env python ########################################################################### # Copyright (C) 2007 Ryan Kavanagh # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation; either version 2 of the License, or # # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # # with this program; if not, write to the Free Software Foundation, Inc., # # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # You may contact the author at ryanakca@kubuntu@org # ########################################################################### def maximum(list_of_numbers): """ Returns a list of ordered numbers, without using list.sort() Written in order to understand how list.sort() works. """ length = len(list_of_numbers) ordered_list = list_of_numbers[0] for place, item in zip(range(length), list_of_numbers): print place, item if item <= ordered_list[place]: ## /home/ryan/orderedlist.py in maximum(list_of_numbers) ## 25 for place, item in zip(range(length), list_of_numbers): ## 26 print place, item ##---> 27 if item <= ordered_list[place]: ## 28 pass ## 29 else: ## ##TypeError: unsubscriptable object ## ## What is happening? Shouldn't item be compared to the number in the list? pass else: ordered_list.isert(place, item)