SIZES = ('1920x1080', '1600x1200', '1400x1050', '1280x1024', '1280x960', '1152x864', '1024x768',
'3840x2400', '3840x2160', '3840x1200', '2560x1600', '2560x1440', '2560x1080', '2560x1024',
'2048x1152', '1920x1200', '1680x1050', '1600x900', '1440x900', '1280x800', '1280x720', '2160x3840',
'1440x2560', '1366x768', '1080x1920', '1024x600', '960x544', '800x1280', '800x600', '720x1280',
'540x960', '480x854', '480x800', '400x480', '360x640', '320x480', '320x240', '240x400', '240x320',
'2732x2732', '2048x2048', '1024x1024', '750x1334', '640x1136', '640x960', '1280x900')
__slots__
и namedtuple
должно натолкнуть на эти размышления.def cmp(x):
x = x.split('x')
return int(x[0]) * int(x[1])
sorted(SIZES, key=cmp)
SIZES = ('1920x1080', '1600x1200', '1400x1050', '1280x1024', '1280x960', '1152x864', '1024x768',
'3840x2400', '3840x2160', '3840x1200', '2560x1600', '2560x1440', '2560x1080', '2560x1024',
'2048x1152', '1920x1200', '1680x1050', '1600x900', '1440x900', '1280x800', '1280x720', '2160x3840',
'1440x2560', '1366x768', '1080x1920', '1024x600', '960x544', '800x1280', '800x600', '720x1280',
'540x960', '480x854', '480x800', '400x480', '360x640', '320x480', '320x240', '240x400', '240x320',
'2732x2732', '2048x2048', '1024x1024', '750x1334', '640x1136', '640x960', '1280x900')
dct = {int(size.split('x')[0]): size for size in SIZES}
dct_sorted = sorted(dct.items())
for size in dct_sorted:
print(size[1])
SIZES = ('1920x1080', '1600x1200', '1400x1050', '1280x1024', '1280x960', '1152x864', '1024x768',
'3840x2400', '3840x2160', '3840x1200', '2560x1600', '2560x1440', '2560x1080', '2560x1024',
'2048x1152', '1920x1200', '1680x1050', '1600x900', '1440x900', '1280x800', '1280x720', '2160x3840',
'1440x2560', '1366x768', '1080x1920', '1024x600', '960x544', '800x1280', '800x600', '720x1280',
'540x960', '480x854', '480x800', '400x480', '360x640', '320x480', '320x240', '240x400', '240x320',
'2732x2732', '2048x2048', '1024x1024', '750x1334', '640x1136', '640x960', '1280x900')
def str2tuple(arr):
return sorted([(int(item.split('x')[0]), int(item.split('x')[1])) for item in arr])
def tuple2str(arr):
return ["%dx%d" % (item[0], item[1]) for item in arr]
print tuple2str(str2tuple(SIZES))
['240x320', '240x400', '320x240', '320x480', '360x640', '400x480', '480x800', '480x854', '540x960', '640x960', '640x1136', '720x1280', '750x1334', '800x600', '800x1280', '960x544', '1024x600', '1024x768', '1024x1024', '1080x1920', '1152x864', '1280x720', '1280x800', '1280x900', '1280x960', '1280x1024', '1366x768', '1400x1050', '1440x900', '1440x2560', '1600x900', '1600x1200', '1680x1050', '1920x1080', '1920x1200', '2048x1152', '2048x2048', '2160x3840', '2560x1024', '2560x1080', '2560x1440', '2560x1600', '2732x2732', '3840x1200', '3840x2160', '3840x2400']