What is the best way to access the last entered key in a default dict in Python? -


i have default dict of dicts primary key timestamp in string form 'yyyymmdd hh:mm:ss.' keys entered sequentially. how access last entered key or key latest timestamp?

use ordereddict collections module if need access last item entered. if, however, need maintain continuous sorting, need use different data structure entirely, or @ least auxiliary 1 purposes of indexing.

edit: add that, if accessing final element operation have rarely, may sufficient sort dict's keys , select maximum. if have frequently, however, repeatedly sorting become prohibitively expensive. depending on how code works, simplest approach maintain single variable that, @ given point, contains last key added and/or maximum value added (i.e., updated each subsequent addition dict). if want maintain record of additions extends beyond last item, however, , don't require continuous sorting, ordereddict ideal.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -