cpbotha / nvpy

Simplenote syncing note-taking application, inspired by Notational Velocity and ResophNotes, but uglier and cross-platformerer.
Other
849 stars 114 forks source link

Add alphanumeric sort #210

Closed yuuki0xff closed 4 years ago

yuuki0xff commented 4 years ago

See https://groups.google.com/forum/#!topic/nvpy/7Mp_p22dYvA

Expected result:

1
2
2a1
3
4
5
10
10a1
10a10b
20a
yuuki0xff commented 4 years ago

Implemented by aa2fad958ba87dd0bc7b1e9f2316946f761534ab. To enable this feature, set sort_mode=3 in nvpy.cfg.

Behavior:

In [1]: import nvpy.notes_db                        

In [2]: sorter = nvpy.notes_db.AlphaNumSorter()     

In [3]: input_ = ''' 
   ...: 2a1 
   ...: 5 
   ...: 20a 
   ...: 10 
   ...: 2 
   ...: 10a10b 
   ...: 3 
   ...: 1 
   ...: 4 
   ...: 10a1 
   ...: '''.strip().splitlines()                    

In [4]: sorted(input_, key=lambda x: tuple(sorter._str2elements(x)))                                     
Out[4]: ['1', '2', '2a1', '3', '4', '5', '10', '10a1', '10a10b', '20a']