Results 1 to 5 of 5

Thread: python + list + sort != true

  1. #1
    Join Date
    Nov 2010
    Posts
    29

    Default python + list + sort != true

    will bring this question up again.

    coding an application where i put information into a list(language python).
    but before i really put the information into the list i would like to sort it in another way then just the "append" way.
    Since every item will be put last into the list i would really like to order it by A-Z or Z-A or whatever.
    i tried(written from my head):

    items = ListItems()
    item.Label("test")
    items.append(item)

    items.sort()
    sorted(items, key=attrgetter('GetLabel'))

    but none of the 2 last entries will successfully change the order of the list.
    Does anyone know any way to sort the items in other way then the "append"-way?

    can also say that neither items.insert(item, 0) work :S. kind of wierd since its included in pyhon 2.4

  2. #2
    Join Date
    Oct 2010
    Posts
    18

    Default Could do something like..

    import operators
    list = []
    #add a bunch of stuff to the list - list.append(("jwilson11",29))
    list.sort(key=operator.itemgetter(1))
    #this will sort by the 2nd item in your tuple, in this case age
    #then you can just loop your list and add the items to your boxee list
    uilist = mc.ListItems()
    for i in list:
    item = mc.ListItem(mc.ListItem.TYPE)
    item.SetLabel(i[0] + ' ' + i[1])
    uilist.append(item)
    mc.GetActiveWindow().GetList(9000).SetItems(uilist )


    didn't try any of that as I am at work, but I think it should work

  3. #3
    Join Date
    Nov 2010
    Posts
    29

    Default array -> array

    ah, so basically you making an array for all info you need and then but it into diffrent subarrays to listitems.

    will try it in a min and see

  4. #4
    Join Date
    Nov 2010
    Posts
    29

    Default sweet

    thanks a bunch.. works great, feeling kinda stupid not thinking "out-side-the-box"

  5. #5
    Join Date
    Oct 2010
    Posts
    18

    Default

    No problem, glad it worked for you

Similar Threads

  1. Creating a list in python
    By Swiftfeet8 in forum boxee applications
    Replies: 4
    Last Post: April 18th, 2011, 10:49 PM
  2. Simple Python generated list
    By sprzybilla in forum boxee applications
    Replies: 1
    Last Post: December 12th, 2010, 06:50 AM
  3. From Python to List.
    By Govan89 in forum boxee applications
    Replies: 33
    Last Post: June 24th, 2010, 05:31 AM
  4. Setting boxee view/sort options in Python plugin
    By nerdlinger in forum boxee applications
    Replies: 3
    Last Post: March 1st, 2010, 05:28 AM
  5. List in Python
    By 56Killer in forum boxee applications
    Replies: 1
    Last Post: June 20th, 2009, 11:25 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •