×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    27

    Multidimenstion list

    i am using multidimention list in my python application. i need to sort it on column bassis.

    here is my list example

    list = [
    ['a','b',2,3,5],
    ['a','b',5,6,5],
    ['a','b',2,2,7],
    ['a','b',8,7,1],
    ]

    suppose i want to sort it on column 3 (i.e. index=2).
    i have tried
    list.sort(key = lambda x:x[2])
    it works in python ide, but sows error in mobile emulator that "typeerror: sort() takes no keyword argument"

    i tried another option of

    from operator import itemgetter
    list.sort(key=itemgetter(2))


    it also works in python ide , but in mobile emulator "type error: itemgetter is not defined"

    any idea to this problm ?
    please help as soon as possible...

    thaks.
    chirag k gadara.
    Software Developer.
    Auromeera Technometrix Pvt. Ltd.

  2. #2
    Regular Contributor
    Join Date
    Sep 2005
    Location
    Finland, Helsinki
    Posts
    323

    Re: Multidimenstion list

    Quote Originally Posted by mindstien View Post
    i am using multidimention list in my python application. i need to sort it on column bassis. here is my list example
    list = [
    ['a','b',2,3,5],
    ['a','b',5,6,5],
    ['a','b',2,2,7],
    ['a','b',8,7,1],
    ]

    suppose i want to sort it on column 3 (i.e. index=2).
    Google "python DSU". Or try this (copy/paste to python shell):

    Code:
    def dsu_sort(list, index):
      newlist = [ (item[index], item) for item in list ]
      newlist.sort()
      list[:] = [ item for (name, item) in newlist ]
    
    list = [
    ['a','a',2,3,5],
    ['x','a',5,6,5],
    ['e','d',2,2,7],
    ['g','f',8,7,1],
    ]
    dsu_sort(list,4)
    print list # now sorted by last column

  3. #3
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,795

    Re: Multidimenstion list

    Hi mindstien,

    For posting code in the dicussions you may use the CODE tags (#)
    That help others to understand your code easily and respond to your problem faster. Indentations are mantained when you post your code using the code tags

    Best Regards
    Croozeus
    Pankaj Nathani
    www.croozeus.com

Similar Threads

  1. File Browsing Problem
    By Marwa in forum Mobile Java Networking & Messaging & Security
    Replies: 13
    Last Post: 2007-10-10, 15:52
  2. Change the List type of the LIST ???
    By divyas in forum Mobile Java General
    Replies: 2
    Last Post: 2006-09-15, 20:27
  3. 6680 and bluetooth service profiles
    By ceruault in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2005-10-08, 22:24
  4. Bluetooth Virtual Serial Port
    By mealos in forum Bluetooth Technology
    Replies: 2
    Last Post: 2004-12-03, 03:46
  5. List item selection
    By SanDan in forum Mobile Java General
    Replies: 2
    Last Post: 2003-05-06, 10:57

Posting Permissions

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