diff --git a/src/utils.py b/src/utils.py index 346f8062e..ae89259ce 100755 --- a/src/utils.py +++ b/src/utils.py @@ -323,10 +323,10 @@ def be(i): def sortBy(f, L, cmp=cmp): """Uses the decorate-sort-undecorate pattern to sort L by function f.""" for (i, elt) in enumerate(L): - L[i] = (f(elt), elt) + L[i] = (f(elt), i, elt) L.sort(cmp) for (i, elt) in enumerate(L): - L[i] = L[i][1] + L[i] = L[i][2] def mktemp(suffix=''): """Gives a decent random string, suitable for a filename.""" diff --git a/test/test_utils.py b/test/test_utils.py index a30a2d5fd..7a9ac44ee 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -177,6 +177,9 @@ class UtilsTest(unittest.TestCase): self.assertEqual(L, ['z', 'AD', 'abc']) utils.sortBy(str.lower, L) self.assertEqual(L, ['abc', 'AD', 'z']) + L = ['supybot', 'Supybot'] + utils.sortBy(str.lower, L) + self.assertEqual(L, ['supybot', 'Supybot']) def testNItems(self): self.assertEqual(utils.nItems(1, 'tool', 'crazy'), '1 crazy tool')