Hi Birkenfeld
danke für die Antwort. Um nun mal konkreter zu werden:
unter verwendung von:
Code: Alles auswählen
def reorder_images(images,reverse=False):
images.sort(key=lambda x: (len(x[1].strip('0')), x[1].count('1')))
return images
wobei images eine Liste von Tupels (<filename>,<fingerprint>) ist, ergibt sich:
DEBUG:root:Loading image db
DEBUG:root:BEFORE ORDERING
DEBUG:root:0002.jpg -> 0010101101111011111110110001011110100001000000110000000111010001
DEBUG:root:0004.jpg -> 0111111101111001010010110000000000000111000000110000000110000111
DEBUG:root:0006.jpg -> 1111110011101101111101101100100000001011000100010000001000110100
DEBUG:root:0008.jpg -> 1111001111111111111101111111111100100011001001110000011100000111
DEBUG:root:0011.jpg -> 1111111111111111111111101110111111101011111111110001111100111111
DEBUG:root:0013.jpg -> 1111111111111111111111111111111111000011011110111011111000001011
DEBUG:root:0015.jpg -> 1111000111111100000010100000111000000100000011000000111110001011
DEBUG:root:0003.jpg -> 1011111110100001101110111111111100000111100100110000011100000101
DEBUG:root:0005.jpg -> 1111111111111000111011111111001100000101001111110000011100000011
DEBUG:root:0001.jpg -> 1111111000011111001111110011111101111101111111111110001111100001
DEBUG:root:0007.jpg -> 1111111111111111111111101111110010011001100001011000110111000111
DEBUG:root:0009.jpg -> 1110000011111111111111111100011100001111000000100000000101111111
DEBUG:root:0010.jpg -> 1111101111111011111010111111111111111111111111111111111011001110
DEBUG:root:0012.jpg -> 1100000011111110111111111110011101101011001110110001111001101111
DEBUG:root:0014.jpg -> 0111111101111110111111101111011111111111111100111111011011110110
DEBUG:root:Sorting images
DEBUG:root:Done
DEBUG:root:AFTER SORTING
DEBUG:root:0006.jpg -> 1111110011101101111101101100100000001011000100010000001000110100
DEBUG:root:0002.jpg -> 0010101101111011111110110001011110100001000000110000000111010001
DEBUG:root:0014.jpg -> 0111111101111110111111101111011111111111111100111111011011110110
DEBUG:root:0004.jpg -> 0111111101111001010010110000000000000111000000110000000110000111
DEBUG:root:0010.jpg -> 1111101111111011111010111111111111111111111111111111111011001110
DEBUG:root:0015.jpg -> 1111000111111100000010100000111000000100000011000000111110001011
DEBUG:root:0003.jpg -> 1011111110100001101110111111111100000111100100110000011100000101
DEBUG:root:0009.jpg -> 1110000011111111111111111100011100001111000000100000000101111111
DEBUG:root:0005.jpg -> 1111111111111000111011111111001100000101001111110000011100000011
DEBUG:root:0008.jpg -> 1111001111111111111101111111111100100011001001110000011100000111
DEBUG:root:0012.jpg -> 1100000011111110111111111110011101101011001110110001111001101111
DEBUG:root:0007.jpg -> 1111111111111111111111101111110010011001100001011000110111000111
DEBUG:root:0001.jpg -> 1111111000011111001111110011111101111101111111111110001111100001
DEBUG:root:0013.jpg -> 1111111111111111111111111111111111000011011110111011111000001011
DEBUG:root:0011.jpg -> 1111111111111111111111101110111111101011111111110001111100111111
Nicht ganz was ich erwartet hätte. Besonders interessant ist der Vergleich von 0006.jpg und 0014.jpg.
db['0006.jpg'].count('1') = 30
db['0014.jpg'].count('1') = 53
Trotzdem würde ich aufgrund der '0'en an den Rändern 0014 vor 0006 erwarten
birkenfeld hat geschrieben:Um mal bei der gestellten Aufgabe zu bleiben (ohne zu beurteilen, ob die Anwendung sinnvoll ist):
Code: Alles auswählen
x.sort(key=lambda x: (len(x.strip('0')), x.count('1')))
sollte das gewünschte ergeben, wobei `x` eine Liste mit den einzelnen Zeilen ist.