Skip to content

Commit 430dd84

Browse files
committed
-
1 parent 628f4aa commit 430dd84

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

source_py2/python_toolbox/misc_tools/misc_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def decimal_number_from_string(string):
358358
'''
359359
if isinstance(string, bytes):
360360
string = string.decode()
361-
if not isinstance(string, str):
361+
if not isinstance(string, basestring):
362362
raise Exception("%s isn't a decimal number." % string)
363363
if not _decimal_number_pattern.match(string):
364364
raise Exception("%s isn't a decimal number." % string)

source_py2/python_toolbox/nifty_collections/ordered_dict.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,29 @@
1414

1515
class OrderedDict(StdlibOrderedDict):
1616

17+
def move_to_end(self, key, last=True):
18+
'''Move an existing element to the end (or beginning if last==False).
19+
20+
Raises KeyError if the element does not exist.
21+
When last=True, acts like a fast version of self[key]=self.pop(key).
22+
23+
'''
24+
link = self.__map[key]
25+
link_prev = link[0]
26+
link_next = link[1]
27+
link_prev[1] = link_next
28+
link_next[0] = link_prev
29+
if last:
30+
last = self.__root[0]
31+
link[0] = last
32+
link[1] = self.__root
33+
last[1] = self.__root[0] = link
34+
else:
35+
first = self.__root[1]
36+
link[0] = self.__root
37+
link[1] = first
38+
root[1] = first[0] = link
39+
1740
def sort(self, key=None, reverse=False):
1841
'''
1942
Sort the items according to their keys, changing the order in-place.

0 commit comments

Comments
 (0)