From: Ian B. <ia...@co...> - 2005-11-21 18:31:09
|
Oleg Broytmann wrote: > def sorted_items(a_dict): > if isinstance(a_dict, dict): > a_dict = a_dict.items() > E return sorted(a_dict, key=lambda t: sort_name(t[0])) > >> NameError: global name 'sorted' is not defined > > > [/home/phd/work/SQLObject/SQLObject-trunk-decimal/sqlobject/events.py:198] > > There is no sorted() in Python 2.2 and 2.3. Ah, yes; try: sorted except NameError: def sorted(lst, cmp=None, key=None): if key: lst = [(key(i), i) for i in lst] lst = lst[:] if cmp: lst.sort(cmp) else: lst.sort() if key: return [i for k, i in lst] else: return lst It's not a complete sorted implementation, but it should work for this. -- Ian Bicking / ia...@co... / http://blog.ianbicking.org |