sort items in list. help required
#1
I have a list of links returned as

[('L5SZP8M8', 'S1E11 - Tigh Me Up, Tigh Me Down'), ('5R6RVRXL', 'S1E05 - The Hand of God')]

as you can see there are episodes. I have retreived a list and would like to sort them so S01E05 comes before S01E11

I have seen in the internet a Sorted function but not really sure how it works.

Any help appreciated.

tks
Reply
#2
Hi, I've been trying to use addSortMethod with an add-on I'm working on and the only methods I've been able to get to work are LABEL and UNSORTED.

Try adding these two lines to your script.
Code:
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_LABEL)
Reply
#3
divingmule Wrote:Hi, I've been trying to use addSortMethod with an add-on I'm working on and the only methods I've been able to get to work are LABEL and UNSORTED.

Try adding these two lines to your script.
Code:
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_LABEL)

so i would do

test = [('L5SZP8M8', 'S1E11 - Tigh Me Up, Tigh Me Down'), ('5R6RVRXL', 'S1E05 - The Hand of God')]

xbmcplugin.addSortMethod(int(test), xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(int(test), xbmcplugin.SORT_METHOD_LABEL)

is this correct.?
Reply
#4
Sorry:o , I guess there are many ways to sort a list. http://wiki.python.org/moin/HowTo/Sorting
addSortMethod sorts the addItem in the plugin directory.
Reply
#5
divingmule Wrote:Sorry:o , I guess there are many ways to sort a list. http://wiki.python.org/moin/HowTo/Sorting
addSortMethod sorts the addItem in the plugin directory.

The one i was looking at is

>>> student_tuples = [
('john', 'A', 15),
('jane', 'B', 12),
('dave', 'B', 10),
]
>>> sorted(student_tuples, key=lambda student: student[2]) # sort by age
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]

But dont understand key=lambda student: student[2]
Reply
#6
I'm not sure I understand it all either Smile but this seems to work.
Code:
>>> test_tuples = [('L5SZP8M8', 'S1E11 - Tigh Me Up, Tigh Me Down'), ('5R6RVRXL', 'S1E05 - The Hand of God'), ('4lsejfiao42d4', 'S1E04 - something unknown')]
>>> sorted(test_tuples, key=lambda test: test[1])
[('4lsejfiao42d4', 'S1E04 - something unknown'), ('5R6RVRXL', 'S1E05 - The Hand of God'), ('L5SZP8M8', 'S1E11 - Tigh Me Up, Tigh Me Down')]
Reply
#7
divingmule Wrote:I'm not sure I understand it all either Smile but this seems to work.
Code:
>>> test_tuples = [('L5SZP8M8', 'S1E11 - Tigh Me Up, Tigh Me Down'), ('5R6RVRXL', 'S1E05 - The Hand of God'), ('4lsejfiao42d4', 'S1E04 - something unknown')]
>>> sorted(test_tuples, key=lambda test: test[1])
[('4lsejfiao42d4', 'S1E04 - something unknown'), ('5R6RVRXL', 'S1E05 - The Hand of God'), ('L5SZP8M8', 'S1E11 - Tigh Me Up, Tigh Me Down')]

yep thats perfect.

Done the Movies side to TVShack (List A-Z ,Recent,Popular,Last searched & search function) now onto the TV section....which is why i needed the sort function as none are in Episodes are in a good order.
Reply

Logout Mark Read Team Forum Stats Members Help
sort items in list. help required0