You Are Here:

Community: Developer Discussion Boards

#1 Old Multidimenstion list - 2008-01-28, 07:40

Join Date: Jul 2007
Posts: 27
mindstien
Offline
Registered User
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.
Reply With Quote

#2 Old Re: Multidimenstion list - 2008-01-28, 15:11

Join Date: Sep 2005
Posts: 314
Location: Finland, Helsinki
aaaaapo
Offline
Regular Contributor
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
Reply With Quote

#3 Old Re: Multidimenstion list - 2008-01-28, 15:42

Join Date: May 2007
Posts: 2,737
Location: 21.46 N 72.11 E
croozeus's Avatar
croozeus
Offline
Forum Nokia Champion
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
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
File Browsing Problem Marwa Mobile Java Networking & Messaging & Security 13 2007-10-10 16:52
Change the List type of the LIST ??? divyas Mobile Java General 2 2006-09-15 21:27
6680 and bluetooth service profiles ceruault Mobile Java Networking & Messaging & Security 1 2005-10-08 23:24
Bluetooth Virtual Serial Port mealos Bluetooth Technology 2 2004-12-03 04:46
List item selection SanDan Mobile Java General 2 2003-05-06 11:57

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d81449X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ