Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # sort_by_many_attributes_demo.py ^ got around a glitch
- sss = [
- ('',('tmp', 'bmp', 1000, 1200, 1200)),
- ('',('xyz', 'jpg', 600, 1200, 720)),
- ('',('123', 'jpg', 600, 1000, 600)),
- ('',('foo', 'jpg', 800, 1000, 800)),
- ('',('25', 'jpg', 800, 800, 640)),
- ('',('bar', 'gif', 1000, 800, 800)),
- ('',('abc', 'jpg', 600, 800, 480)),
- ('',('456', 'gif', 800, 1200, 960)),
- ('',('s25', 'gif', 1000, 1000, 1000))]
- options = '1:Filename 2:Type 3:Width 4:Height 5:Size'.split()
- def keyattr():
- for s in sss: print str(s[0])+'\t\t\t%s\t%s\t%s\t%s\t%s'%(s[1])
- return raw_input("\nSort List By... \
- \n"+' '.join(options)+" (Q:To Exit) \
- \nAnd Re-Enter Attribute # To Reverse The Order. \
- \nKey Selection ::: ")
- choice = keyattr()
- while choice.lower() != 'q':
- if choice in '12345':
- i = int(choice)-1
- ttt = []
- tmp = []
- for s in sss: ttt.append((s[-1][i],s[0],s[-1]))
- ttt = sorted(ttt)
- for t in ttt: tmp.append((t[0],t[-1]))
- for s in range(len(sss)):
- if sss[s][1][i] != tmp[s][1][i]: sss=tmp; tmp=1; break
- if tmp != 1: sss=sss[::-1] # sss=reversed(sss, reverse=True) as also sss=reversed(sss) does not work properly
- print;print
- print 'Option -- '+options[i]+'\n'
- choice = keyattr()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement